Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:01
Show Gist options
  • Save adojos/e6f600a3b1a02f47b55372176a451749 to your computer and use it in GitHub Desktop.
Save adojos/e6f600a3b1a02f47b55372176a451749 to your computer and use it in GitHub Desktop.
Java: Sort List Using Collections.sort with Comparator #java
public static void usingCollectionsSortWithComparator() {
List<Integer> input = Arrays.asList(34,12,67,8,91,54,24);
Collections.sort(input,(num1,num2) -> num2-num1);
System.out.print("Sorted List:");
input.forEach(num -> System.out.print(num+" "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment