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) -> e2, LinkedHashMap::new) ); </character>
2
Q
A