Java program to sort map by value

This article will help you to understand “Java program to sort map by value”.

In Sorting any Map like HashMap by value, we can use Comparator which compares by value and not by key.

This program will sort values in Descending order. To sort it in ascending order, just swap o1 and o2 in return statement of compare.

Java Program to sort a map by value


Mobile–> 50 Speaker–> 40 Television–> 30 Bluetooth–> 20 Laptop–> 10

Leave a Reply

Your email address will not be published. Required fields are marked *