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
It's good to share...Share on FacebookTweet about this on TwitterShare on LinkedInPin on PinterestShare on Google+Email this to someone

Leave a Reply

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