Investors can profit from stock investing through price appreciation and collecting dividends. The latter is an important component in an equity investment's total return.

It's important to pick stocks that have growth prospects and the ability to sustain dividend payments, which isn't easy.

Walmart (WMT 1.72%) and McDonald's (MCD 0.63%) should top your list of stocks to aggressively buy for long-term appreciation and dividends.

Someone examining data while price charts remain on monitors.

Image source: Getty Images.

1. Walmart

It's tough to find retail companies like Walmart that have maintained a company advantage for decades. Often, they achieve a level of success before fading from the scene. These include once-popular destinations like Sears.

Walmart has a simple formula that it has employed since opening its first discount store more than six decades ago. That's to keep costs down and pass those savings along to customers in the form of low prices.

That continues to drive shoppers to its stores and website. Fiscal second-quarter same-store sales (comps) at the key Walmart U.S. unit increased 4.6%. Higher traffic contributed 1.5 percentage points with increased spending responsible for the balance. The quarter ended on July 31.

The business generates plenty of operating cash flow to invest in capital expenditures that allow Walmart to remain competitive. This includes technology investments that improve shoppers' experience by allowing efficient online ordering and faster delivery.

Walmart produced first-half free cash flow (FCF), or operating cash flow less capital expenditures, of $6.9 billion. That left it a nice cushion to pay the $3.8 billion in dividends.

Early this year, the board of directors increased the quarterly dividend by an impressive 13%, running its streak to 52 straight years. That makes Walmart a Dividend King, although you can find stocks with a higher dividend yield than its 0.9%.

This year, through Sept. 8, the stock's 13.3% gain has beaten the S&P 500 index's 10.4%.

Walmart's stock has a P/E of 38 compared to the S&P 500's 30. However, with the company's consistently strong performance, investments designed to stay ahead of the competition, and reliably higher dividends, I believe Walmart deserves a higher valuation.

2. McDonald's

Most people know McDonald's and its fast-food fare. A global presence, you don't have to travel far before seeing its trademark golden arches.

It also operates the business in a capital-efficient manner. That's because it doesn't own most of its restaurants. Rather, the company franchises about 95% of its roughly 44,000 locations, which means McDonald's isn't responsible for upkeep or operating costs. The parent company collects a percentage of sales and rent if it owns the land.

The restaurants remaining a popular eating destination clearly benefits McDonald's. While the company has been affected by consumers slowing discretionary spending, its recent comps turned positive, increasing 3.8% in the second quarter. Management previously made missteps by charging too much for certain menu items, but it looks like it's taking corrective action. That includes adding value items. That should result in traffic returning and accelerated sales growth.

In the meantime, McDonald's produced $3.1 billion in FCF during the first half of the year. That's much higher than the $2.5 billion in dividends the company paid.

The company hasn't become a Dividend King yet, but it's on its way. Last September, the board of directors made it 48 straight years when it raised the payout by 6%. The stock has a 2.3% dividend yield, nearly double the S&P 500's 1.2%.

Year to date, McDonald's shares gained 7.9%, trailing the S&P 500 by about 2.5 percentage points. While the P/E ratio has increased slightly from 25 to 26, the stock trades at a lower valuation than the S&P 500. Returning to its roots of affordable menu items should result in faster sales and earnings growth. In the meantime, you can collecting an above-market dividend yield.