Skip to content

Commit 3c05cfe

Browse files
committed
Add DuplicateElements class to identify and print duplicate elements from a list using streams
1 parent 57c2512 commit 3c05cfe

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.java8;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.List;
6+
import java.util.Set;
7+
8+
public class DuplicateElements {
9+
public static void main(String[] args) {
10+
List<Integer> myList = Arrays.asList(10, 15, 8, 49, 25, 98, 98, 32,
11+
15);
12+
Set<Integer> uniqueSet = new HashSet<>();
13+
myList.stream().filter(x->!uniqueSet.add(x)).forEach(System.out::println);
14+
15+
}
16+
}

0 commit comments

Comments
 (0)