fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. import java.util.Map;
  9. import java.util.function.Function;
  10. import java.util.stream.Collectors;
  11.  
  12. /* Name of the class has to be "Main" only if the class is public. */
  13. class Ideone
  14. {
  15. public static void main (String[] args) throws java.lang.Exception
  16. {
  17. List<Integer> integers = Arrays.asList(4, 5, 7, 3, 5, 4, 2, 4);
  18. Map<Integer, Long> grouping = integers.stream()
  19. .collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
  20. grouping.values().removeIf(c -> c > 1);
  21. System.out.println(grouping.keySet());
  22. }
  23. }
Success #stdin #stdout 0.09s 34264KB
stdin
Standard input is empty
stdout
[2, 3, 7]