Comparator… A comparison function that performs global ordering in a collection
public static void main(String[] args) {
List<String> list = Arrays.asList("apple","melon","banana","cherry","orange");
Collections.sort(list, Comparator.naturalOrder());
System.out.println(list);
}
public static void main(String[] args) {
List<String> list = Arrays.asList("apple","melon","banana","cherry","orange");
Collections.sort(list, Comparator.reverseOrder());
System.out.println(list);
}
Recommended Posts