While retail chains struggle across the United States, Dollar General  (DG)  and other discounters are thriving.

Dollar General posted an impressive 2.2% increase in first-quarter same-store sales. Its earnings per share smashed expectations at $1.03, a 23% increase from a year earlier. And for each of the past seven quarters, quarterly sales growth has been at least 7%.

Likewise, Dollar General competitor Dollar Tree  (DLTR) saw a 2.3% increase in same-store sales for its latest quarter.

As consumer spending habits change, Dollar General and other discount retailers are in a strong position to take advantage. And investors still interested in the retail segment should look at discount retailers as the wave of the future instead of struggling larger stores.

For years, discount retailers have fought an image as stores where seniors and struggling families shop. But millennials are spending their money in dollar stores, too.

Millennials make up 12% of Dollar General shoppers but account for 24% of sales, according to Fortune.

How has Dollar General managed to thrive while bigger stores haven't? One advantage is that Dollar General has more than 12,400 stores, and it plans to build another 900 by next year.

Walmart, by comparison, has 5,163 stores.

Millennial customers want to save money, but they by and large aren't interested in a massive shopping trip where they save by buying in bulk. Instead, they would rather buy what they need, a little bit at a time, at a store that is close by.

Furthermore, most online retailers offer free shipping or some other bonus when customers purchase a certain amount, which encourages them to buy in bulk and creates competition for the big-box stores.

This doesn't mean that discount retailers can just brush off online shopping, however. Online dollar store Hollar launched just six months ago but has already reached $1 million in retail sales, and it offers recognizable brands as opposed to low-quality merchandise.

Meanwhile, discount retailers are making changes to ensure that they continue to appeal to millennials.

Dollar General, for instance, recently launched Heartland Harvest, a healthy food brand that is aimed at millennials. The retailer plans to have 15 products under the brand name by September.

The discount retailer is also looking for ways to improve its smartphone application. Although no details have been disclosed, this demonstrates Dollar General's commitment to younger customers.

So what should investors conclude about investing in Dollar General and Dollar Tree? Both stocks rose after they released impressive first-quarter results, with Dollar Tree jumping from $75.56 last week to $90.28 on Tuesday.

Despite competition from Hollar, investors should buy these stocks, especially Dollar General, which is working hard to maintain the loyalty of millennials.

This article is commentary by an independent contributor. At the time of publication, the author held no positions in the stocks mentioned.

More from Opinion

Netflix's Big Price Hike Could Add More Than $1 Billion to Its Annual Revenue

Netflix's Big Price Hike Could Add More Than $1 Billion to Its Annual Revenue

CES Takeaways for AMD and Intel, Alibaba and JD.com and Augmented Reality

CES Takeaways for AMD and Intel, Alibaba and JD.com and Augmented Reality

CES Takeaway: 5G Is More About Nuts-and-Bolts Improvements - For Now

CES Takeaway: 5G Is More About Nuts-and-Bolts Improvements - For Now

CES Takeaway: As Internet of Things Grows, Chipmakers Stand to Benefit

CES Takeaway: As Internet of Things Grows, Chipmakers Stand to Benefit

3 Things to Know at the Market Close: The Retail Rundown and More

3 Things to Know at the Market Close: The Retail Rundown and More