How to do this:
int size = ...
var a = new ArrayList<String>();
for (Map.Entry<String,Integer> e : myHashMap) {
a.add( String.format("%s %.3f", e.getKey(), 100.0 * e.getValue() / size));
}
:using Stream
?
int size = ...
var a = myHashMap.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.map(Map.Entry::getValue)
.toList();
How to both getValue
and getKey
and combine them using String.format
?
You need to sign in to view this answers