sorting - Java stream sort 2 var

2018-04-29  本文已影响0人  抽刀断水2
import static java.util.Collections.reverseOrder;
import static java.util.Comparator.comparing;

list = list.stream().sorted(
                        comparing(AClass::getSeq1)
                       .thenComparing(reverseOrder(comparing(AClass::getSeq2))))
                       .collect(toList());


//or you could also write:

list = list.stream().sorted(
                        comparing(AClass::getSeq1)
                       .thenComparing(comparing(AClass::getSeq2).reversed()))
                       .collect(toList());
https://stackoverflow.com/questions/30382453/java-stream-sort-2-variables-ascending-desending
上一篇下一篇

猜你喜欢

热点阅读