java - java8 Hashmap sort error -


this question has answer here:

i have map:

private map<string, atomicinteger> keywordmap = new hashmap<string, atomicinteger>(); 

i'm trying sort map value (atomicinteger), in java 8, following code:

keywordmap         .entryset()         .parallelstream()         .sorted().foreachordered(e -> system.out.print(e.getkey())); 

however, i'm getting following error:

java.lang.classcastexception: java.util.hashmap$node cannot cast java.lang.comparable 

the error occurs in line: .foreachordered(e -> system.out.print(e.getkey()));

what wrong code?

try use:

stream<map.entry<k,v>> keywordmap = keywordmap.entryset().stream().sorted(map.entry.comparingbyvalue()); 

Comments