If you're tired of keeping constant tabs on the market and just want to buy shares of some quality companies and tuck them away for a while, great! This strategy will probably generate better results for you than a more active approach.

To this end, here's a rundown of three top prospects you can safely buy and hold for 20 years (or more). Notice how all of them are in areas that will always be in demand, or are companies that can adapt to unforeseeable changes to the marketplace.

1. Microsoft

Just as nobody knew what the computing landscape of today was going to look like 20 years ago, we can only guess what it will look like 20 years from now. But it's a pretty good bet that Microsoft (MSFT -1.84%) will remain at the heart of it.

You know the company. Indeed, you're likely using one of its core products right now. Microsoft's Windows operating system is installed on 75% of the world's desktops and laptops, according to data from GlobalStats, and that market share appears to be stabilizing after falling back from more than 90% a decade ago when smartphones and Macs became a more mainstream way of interfacing with the web. By and large, most of the developed world still needs computers; Windows-based software is how the world's collectively agreed to get the most out of them.

It's not just operating systems, though. Microsoft's got plenty of cloud computing solutions, too. Technology market research Canalys says Microsoft's cloud computing platform is the world's second-most popular public cloud option, accounting for 22% of the cloud market's total revenue.

The software giant also operates a video gaming franchise (Xbox), sells its own branded laptops (Surface), owns a professional networking website (LinkedIn), and is the name behind one of the planet's most popular office productivity software suites (Office). All of these profit centers face competition. But all of them are going to be tough to unseat now that consumers and corporations are in the habit of having access to these offerings.

There is one evolution that will certainly be interesting to check on 20 years from now, however. That's the changing nature of Microsoft's business model. It's continuing to pivot from one-time sales of digital technology and toward more subscription-based products. While recurring revenue rarely generates tremendous revenue growth, there's much to be said for reliable, predictable revenue. 

2. Walmart

There was a time not too long ago when it looked like Walmart (WMT -0.65%) was on the ropes. Poorly stocked stores were common, employees were largely disengaged, and Amazon was eating its proverbial lunch when it came to e-commerce.

Then CEO Doug McMillon implemented a top-down overhaul. While it would be a stretch to suggest the world's biggest brick-and-mortar retailer has become everything he'd like for it to be, there's no denying the company is in a much better situation than just a few years ago.

Look for more of this evolution in the future.

The company's never put it quite in these words, but Walmart is becoming more than a mere retailer. It's turning into a lifestyle company. Online shopping and delivery are now mostly seamless, made even more so by its Prime-like delivery subscription service, Walmart+. The retailer is also widening its net, with full-blown health clinics, allowing select third-parties to sell their goods on Walmart's online marketplace, and developing its own high(ish)-end private label wines. The company's latest round of store remodels is also emphasizing fashion, making them look less like a Walmart and more like a clothing store you'd expect to find at a mall.

None of these initiatives are game changers in and of themselves. Collectively, though, they're representative of a much bigger shift in how Walmart is positioning itself with consumers. These brilliant changes should deliver returns well beyond the point when McMillon steps down and his successor takes the helm.

3. Merck

Finally, add Merck (MRK -0.11%) to your list of stocks to buy and hold if you've got an idle $5,000 (or any other amount) lying around.

Just like Walmart and Microsoft, Merck's business is ever-adaptable -- just in a different way. All of the drugs currently in the company's product portfolio will be obsolete and no longer patent-protected in 20 years' time. But the pharmaceutical giant will spend the entirety of that 20-year span working to refill its pipeline for that eventuality.

We've certainly seen it happen before. While cancer-fighting drug Keytruda currently accounts for about a third of its total revenue, it didn't even exist in 2003. At that time, Merck's best-selling drug was Zocor, a statin. Almost a couple decades before that, high-blood pressure treatment Vasotec was the company's big breadwinner.

The point is the pharmaceutical specialist has proven it's willing and able to identify and capitalize on new opportunities as they arise.

Then there's the X factor that makes Merck a better choice for investors than so many of its pharma peers. That's its cash stash and the company's capacity to keep the cash spigot turned on. As of the end of September, Merck was sitting on $11.1 billion worth of liquidity and enjoying quarterly operating cash flow of nearly $5 billion. And if that's not enough acquire or develop the new drugs it needs, the company's credit rating is typically strong enough to let it secure debt funding on favorable terms.

The kicker: Merck is also a dividend juggernaut. The stock's current yield of 2.75% is a bit above the market average right now, but more than that, the underlying dividend payment has more than doubled over the course of the past 20 years. There's no reason to think it can't happen again.