简体   繁体   中英

Sort list in reverse order extracted fields in Java

I got htis method:

private <T, V extends Comparable<V>> boolean isColumnSorted(List<T> gridResult, 
           Function<T, V> extractor) {
    List<T> sortedList = new ArrayList<>(gridResult);
    sortedList.sort(Comparator.comparing(extractor));
    return sortedList.equals(gridResult);
}

but i don't know to to change it if I would like to check if the list is sorted descending. Please help. Thanks.

使用Comparatorreversed()方法:

sortedList.sort(Comparator.comparing(extractor).reversed());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM