fork(1) 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.HashMap;
  7.  
  8. class Ideone
  9. {
  10. static long countPairs(int[] a)
  11. {
  12. var m = new HashMap<Integer, Integer>();
  13. for (var x : a)
  14. {
  15. m.compute(x, (, v) -> (v == null) ? 1 : v + 1);
  16. }
  17. return m.values().stream().filter((v) -> v == 2).count();
  18. }
  19. public static void main (String[] args) throws java.lang.Exception
  20. {
  21. System.out.println(countPairs(new int[]{1 ,2 ,0 , 0, 1}));
  22. }
  23. }
Success #stdin #stdout 0.09s 33956KB
stdin
Standard input is empty
stdout
2