The following is an example to sort a list in reverse order (descending) using the Comparator.reverseOrder() in Java.
Java - Comparator.reverseOrder() Example
import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; public class StreamApplication { public static void main(String[] args) { List<String> list = Arrays.asList("10", "Apple", "Zoo", "7", "Ball", "Umbrella", "3", "apple", "cat"); List<String> sortedList = list.stream() .sorted(Comparator.reverseOrder()) .collect(Collectors.toList()); sortedList.forEach(System.out::println); } }
Output
cat apple Zoo Umbrella Ball Apple 7 3 10