I have a map:
private Map<String, AtomicInteger> keywordMap = new HashMap<String, AtomicInteger>();
I'm trying to sort the Map
by value (AtomicInteger
), in Java 8, with the following code:
keywordMap
.entrySet()
.parallelStream()
.sorted().forEachOrdered(e -> System.out.print(e.getKey()));
However, I'm getting the following error:
java.lang.ClassCastException: java.util.HashMap$Node cannot be cast to java.lang.Comparable
The error occurs in this line: .forEachOrdered(e -> System.out.print(e.getKey()));
What is wrong with my code?