Here is what I have, I want to sort in descending a the value in the entry.
Map<String, Outer> outer = Input
.entrySet()
.stream
.collect(toMap(Map.Entry::getKey, entry->{
List<Outer> inner = entry
.getValue()
.stream()
.sorted(Comparator.comparingDouble(???))
})) ... (more lines of code.)
How to write a Comparator with sorted. If want to do the following inside sorted
if (o1.getSomething() > o2.getSomething())
return -1;
if (o1.getSomething() < o2.getSomething())
return 1;
return 0;
After getting the List and sorting it works for me.
inner.sort((Outer o1, Outer o2) -> {
if (o1.getSomething() > o2.getSomething())
return -1;
if (o1.getSomething() < o2.getSomething())
return 1;
return 0;
});
But is there a way to use stream.sorted( " use the same comparator logic here") inside entry.
Entry is an ArrayList, with bunch of values.
entry:[{w:1},{w:2},{w:3},{w:4}];
So I want to reverse sort this, to be as follows:
entry:[{w:4},{w:3},{w:2},{w:1}];
so the final list I get is a sorted in reverse order one.
sry for the confusion.