在第一个示例中,
reversed将其应用于整个比较器,该比较器按升序比较seq1和seq2。
您需要的是仅反转第二个比较,例如,可以使用以下方法完成:
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());
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)