Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:08
Show Gist options
  • Save adojos/ca8e437483baa5fa5a1ced46727adcbc to your computer and use it in GitHub Desktop.
Save adojos/ca8e437483baa5fa5a1ced46727adcbc to your computer and use it in GitHub Desktop.
Java: Remove Duplicates from List : Stream #java
public static void usingStream(){
List<Integer> input = Arrays.asList(5,10,15,20,10,5,35,40,10,25);
Stream<Integer> streamWithDuplicates = input.stream();
Stream<Integer> streamWithoutDuplicates = streamWithDuplicates.distinct();
List<Integer> output = streamWithoutDuplicates.collect(Collectors.toList());
for(Integer num:output){
System.out.print(num+" ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment