Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java 8 retrieve all list from object into single list and ignore duplicates

public void
  givenListContainsDuplicates_whenRemovingDuplicatesWithJava8_thenCorrect() {
    List<Integer> listWithDuplicates = Lists.newArrayList(1, 1, 2, 2, 3, 3);
    List<Integer> listWithoutDuplicates = listWithDuplicates.stream()
     .distinct()
     .collect(Collectors.toList());
}
Source by www.baeldung.com #
 
PREVIOUS NEXT
Tagged: #java #retrieve #list #object #single #list #ignore #duplicates
ADD COMMENT
Topic
Name
6+4 =