It's been over a decade since the last U.S. recession hit, and many experts are predicting that the next one could be right around the corner. And if a recession does hit, there's a good chance that the stock market will take a dive. However, recessions are inevitable -- it's just a question of when they'll occur, so it's important for all stock market investors to prepare for them.

The good news is that not all stocks get crushed when they happen. Even during the Great Recession, there were some stocks that performed quite well thanks to their resilient business models. With that in mind, here's why I think Berkshire Hathaway (NYSE:BRK.A) (NYSE:BRK.B) and Apple (NASDAQ:AAPL) are great stocks to have in your portfolio in both good times and bad.

Businessman with umbrella staring at storm over a city.

These two stocks can provide some shelter from an economic storm. Image source: Getty Images.

Ready to capitalize on any market weakness

Berkshire Hathaway, the massive conglomerate led by Warren Buffett, has an impressive track record of outperforming the market during tough times. Since 1965, when Buffett took over, the S&P 500 has produced a negative total return in 12 years. Berkshire has beaten the index in all but two of them.

For starters, Berkshire owns more than 60 subsidiary businesses, most of which are recession-resistant. Just to name a couple, people keep paying their car insurance premiums to GEICO no matter what the economy is doing and people will continue to pay their utility bills to Berkshire Hathaway energy. The same can be said about many of the stocks in Berkshire's $200 billion portfolio.

However, my favorite reason to own Berkshire during the next recession is that although Berkshire has always been a financially flexible company, the company is sitting on more than $122 billion in cash and equivalents. Buffett loves to make savvy investments during tough times -- in fact, Berkshire's profitable investments in Goldman Sachs and Bank of America originated during the last recession. Buffett considers it a massive competitive advantage to be a provider of liquidity when most companies don't have money to spend, and it's tough to disagree. The Bank of America investment alone is worth about $15 billion more than Buffett paid for it.

This time Buffett has tons of cash to put to work -- the current cash stockpile is nearly triple what Berkshire had at the end of 2007 before the last recession hit.

A recession-resistant tech innovator

Consumer electronics giant Apple needs no introduction. Apple and its high-end product line might seem like more of a bet on a strong economy than a recession-protection play. And it's easy to see why people might believe that -- in the current 10-year economic expansion, Apple has delivered a total return of more than 1,100% (more than 28% annualized).

However, there are three good reasons why Apple is a stock you want to own during a recession.

For starters, Apple's customers are extremely loyal to the brand. Sales may certainly drop off during a recession, but unlike most other luxury goods manufacturers, Apple's customers are unlikely to ditch their iPhones and iPads for cheaper alternatives during a tough economy.

Second, Apple's service-based businesses are highly profitable and are growing rapidly. Service revenue from things like Apple Music, the App Store, and others make up just over 20% of the company's revenue now, and with the recent launch of the Apple Card and the upcoming rollout of the Apple TV+ streaming service, it's likely that this percentage will get much larger. The point is that this is a stream of recurring revenue that doesn't depend on people buying more hardware.

Finally, Apple has an extreme amount of financial flexibility. With more than $210 billion of cash and marketable securities, the company would be well positioned to take advantage of a recession just like Berkshire would. Apple hasn't been a big acquirer recently, but I wouldn't be surprised if that changed as valuations dropped.

They're not just for recessions

Here's the best part: Not only are these stocks likely to perform significantly better than the market during recessions, but their businesses also thrive during strong economies. That's why I'm mentioning these two in particular -- if a recession arrives soon, these stocks will help protect you. If it doesn't, and the economic expansion continues, they're poised to grow their profits.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.