Comparateur… Fonction de comparaison qui effectue un tri global dans une 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