import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
public class mytest {
public static void main(String[] args) {
List<Integer> list=Arrays.asList(10,20,10,30,10,20,40,50);
Set<Integer> set = new HashSet();
list.stream().filter(x->!set.add(x)).collect(Collectors.toSet()).forEach(x->System.out.println(x));
}
}
The output will be
20
10