美文网首页
sorting - Java stream sort 2 var

sorting - Java stream sort 2 var

作者: 抽刀断水2 | 来源:发表于2018-04-29 20:30 被阅读0次
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

相关文章

网友评论

      本文标题:sorting - Java stream sort 2 var

      本文链接:https://www.haomeiwen.com/subject/vjdalftx.html