0

How to sort values in a HashMap on basis of values and not on Keys?

4th Sep 2016, 8:26 PM
Sonu Mishra
Sonu Mishra - avatar
3 Réponses
0
In java 8 Map<Integer, String> sortedMap = unsortedMap.entrySet().stream() .sorted(Entry.comparingByValue()) .collect(Collectors.toMap(Entry::getKey, Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
5th Sep 2016, 3:56 AM
WPimpong
WPimpong - avatar
0
will this work ? i mean what is unsortedMap? is it an object?
5th Sep 2016, 4:21 AM
Sonu Mishra
Sonu Mishra - avatar
0
yes, it is unsorted map object.
5th Sep 2016, 4:23 AM
WPimpong
WPimpong - avatar