How to Get all Category list in Magento 2?

You can retrieve all the category lists available in the Magento store starting with category id(1) Root Catalog, Default Category to all the custom created categories.

Retrieve a list of information for the category like category id, attribute set id, parent id, path, position, title, is anchor, is active, include in the menu.

You can achieve functionality using the Catalog module interface Magento\Catalog\Api\CategoryListInterface with getList() method to get a category list.

<?php
namespace Jesadiya\AllCategory\Model;

use Exception;
use Magento\Catalog\Api\CategoryListInterface;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Catalog\Api\Data\CategorySearchResultsInterface;

class AllCategory
{
    /**
     * @var SearchCriteriaBuilder
     */
    private $searchCriteriaBuilder;

    /**
     * @var CategoryListInterface
     */
    private $categoryList;

    public function __construct(
        CategoryListInterface $categoryList,
        SearchCriteriaBuilder $searchCriteriaBuilder
    ) {
        $this->categoryList = $categoryList;
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
    }

    /**
     * Fetch all Category list
     *
     * @return CategorySearchResultsInterface
     */
    public function getAllSystemCategory()
    {
        $categoryList = [];
        try {
            $searchCriteria = $this->searchCriteriaBuilder->create();
            $categoryList = $this->categoryList->getList($searchCriteria);
        } catch (Exception $exception) {
            throw new Exception($exception->getMessage());
        }

        return $categoryList;
    }
}

Fetch Category by iterate over a loop from the result given by the method and first check total Count of the category condition,

$categoryList = $this->getAllSystemCategory();
if ($categoryList->getTotalCount()) {
    foreach ($categoryList->getItems() as $category){
        var_dump($category->getData());
    }
}

Output:
Magento\Catalog\Api\Data\CategorySearchResultsInterface