Maps (HashMap/LinkedHashMap/HashSet) Flashcards

1
Q

Sort hashmap by values and save to linkedhashmap, uses streams API

A
// "map" is the hashmap // uses method reference instead of lambda // sorts desc, (see collections.reverseOder()) Map<character integer> sorted = map
        .entrySet()
        .stream()
        .sorted(Collections.reverseOrder(
                Map.Entry.comparingByValue())
        )
        .collect(
                toMap(Map.Entry::getKey,
                        Map.Entry::getValue,
                        (e1, e2) -&gt; e2,
                        LinkedHashMap::new)
        );
</character>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly