Millennials are hesitant to invest in the stock market, according to a new survey from Bankrate: Only 23 percent of those aged 18 to 37 say that the stock market is the best place to put money they won't need for 10 years or more.

That's significantly less than older generations: 33 percent of Gen X and 38 percent of baby boomers say they prefer investing over other methods of saving, such as cash, real estate or bitcoin. Meanwhile, 30 percent of millennials would choose cash over other methods.

There's a good reason so many millennials are hesitant to put their savings into the stock market: Many have seen investments collapse. "A lot of it is being shell-shocked of coming of age during the financial crisis," Greg McBride, Bankrate's chief financial analyst, tells CNBC Make It.

For older millennials, the 2008 crisis wasn't the first, either, McBride points out. Many also remember the dot com crash of the early 2000's. "To see that once or twice within a period of a few short years understandably scared a lot of investors out of stocks altogether," McBride says.

Bankrate also posits that younger people prefer cash because it's hard to imagine owning funds they won't touch for decades. Young people often focus instead on their more immediate needs, which include record levels of student loan debt and rising housing costs.

"Millennials may avow a love for cash because they are in such desperate need for it," the report says. "With little hope for a pension that half of those over 60 enjoy, 41 percent of millennials have no retirement savings, and just a quarter feel as if their savings are on track for a secure retirement."

Unfortunately, cash isn't a great solution. "You can't save enough to get the nest egg you'll need in retirement without the benefit of the power of compounding" you can get from investments, McBride says. "The buying power of your investments is going to get eaten away by inflation by about 2 percent to 3 percent per year," he adds. "So you've got to earn at least that much to preserve the buying power."

And although the stock market can be volatile, history shows that investing almost always pays off: Over the past 90 years, the average annual return for the S&P 500 is over 9 percent.