Sort Map using Java 8 Stream API
2 min readJul 25, 2021
In this article , we will learn how to sort a Map in java.
Ok. Lets Get Started.
Before Java8 how we can sort the Map (If Map key is primitive data type):
— — — — — — — — — — — — — — — — — — — — — — — — — —
HashMap<Integer, String> mapOfNames = new HashMap<>();
mapOfNames.put(1, “karan”);
mapOfNames.put(5, “vivek”);
mapOfNames.put(19, “sumit”);
mapOfNames.put(8, “abc”);