Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:01
Show Gist options
  • Save adojos/7030080a068b49ba2becc1d53d4cfca9 to your computer and use it in GitHub Desktop.
Save adojos/7030080a068b49ba2becc1d53d4cfca9 to your computer and use it in GitHub Desktop.
Java: Sort List Using Using Stream API #java
public static void usingStreamSort() {
List<Integer> input = Arrays.asList(34,12,67,8,91,54,24);
Stream<Integer> inputStream = input.stream();
Stream<Integer> sortedStream = inputStream.sorted();
List<Integer> output = sortedStream.collect(Collectors.toList());
System.out.print("Sorted List:");
output.forEach(num -> System.out.print(num+" "));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment