Retrieve list of all stores programmatically in Magento 2.

Get list of all the stores in a system Programmatically Magento 2.

Store contains the information regarding, store_id, code, website_id, group_id, name, sort_order and is_active.

You can see all the list from the database table name, store

Interface Provides the functionality:
Magento\Store\Api\StoreRepositoryInterface

<?php
namespace Jesadiya\AllStore\Model;

use Magento\Store\Api\Data\StoreInterface;
use Magento\Store\Api\StoreRepositoryInterface;

class StoreList
{
    /**
     * @var StoreRepositoryInterface
     */
    private $storeRepository;

    public function __construct(
        StoreRepositoryInterface $storeRepository
    ) {
        $this->storeRepository = $storeRepository;
    }

    /**
     * Get Store list
     *
     * @return StoreInterface[]
     */
    public function getAllStoreList(): array
    {
        $storeList = $this->storeRepository->getList();

        return $storeList;
    }
}

Fetch all the store using iterate over a loop from the method,

$stores = $this->getAllStoreList();
foreach ($stores as $store) {
    echo $store->getStoreId(); // store id
    echo $store->getCode(); // store code
    echo $store->getName(); // name
    echo $store->getIsActive(); // is active?
    echo $store->getGroupId(); // group id
    echo $store->getSortOrder(); // Sort Order
}

Output: Array of all the store list in the system.