sorting - Java stream sort 2 variables ascending/desending

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 variables ascending/desending)