Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:01
Show Gist options
  • Save adojos/1b8626182691f03fffbdb697ab8a75c4 to your computer and use it in GitHub Desktop.
Save adojos/1b8626182691f03fffbdb697ab8a75c4 to your computer and use it in GitHub Desktop.
Java: Sort List Using Using List.sort #java
public static void usingListSortWithStrings() {
List<String> input = Arrays.asList("Horse","Cat","Elephant","Giraffe");
input.sort((str1,str2) -> str1.compareTo(str2));
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