I have a nested map Map<String, Map<String, Integer>
for example
("Samsung", ("Note", 30))
("Samsung", ("Galaxy", 20))
("Apple", ("Iphone", 40))
I need to sort the map by inner key alphabetically in descending (in this example case - the model name)
and if two names are equal then I have to sort the inner values in ascending (in this case - the price).
My sorting by far is like this:
map.entrySet().stream.forEach(entry -> entry.getValue().entrySet().stream() .sorted(Comparator.comparing(Map.Entry::getKey, Comparator.reverseOrder()))
And I know I have to add .thenComparing()
, but I don't know how to proceed next.