How to get all the stores programmatically

Use the \Magento\Store\Model\StoreManagerInterface::getStores() method:

By default it is implemented as:

A usage example:

/** @var \Magento\Framework\App\ObjectManager $om */
$om = \Magento\Framework\App\ObjectManager::getInstance();
/** @var \Magento\Store\Model\StoreManagerInterface|\Magento\Store\Model\StoreManager $storeManager */
$storeManager = $om->get('Magento\Store\Model\StoreManagerInterface');
$storeManager->getStores($withDefault = false);

See also: