I have one Map<String,Integer>, and it is sorted by value as follows:
set = map.entrySet();
list = new ArrayList<Map.Entry<String, Integer»(set);
Collections.sort( list, (o1, o2) -> (o2.getValue()).compareTo( o1.getValue() ));
I already have a sorted integer list from this map:
word_used = new ArrayList<Integer>(map.values()
.stream()
.sorted()
.collect(Collectors.toList()));
Collections.reverse(word_used);
But how can I get a list of strings that will be sorted equal to Map (by value)?
I mean, if I have a map with elements:
map.put("eggs",1500);
map.put("echo",150);
map.put("foo",320);
map.put("smt",50);
and sort it as:
eggs : 1500
foo : 320
echo : 150
smt : 50
I need to get 2 lists:
eggs
foo
echo
smt
and
1500
320
150
50
source
share