fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.stream.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13.  
  14.  
  15. Map<Integer, String> a = new HashMap<>();
  16. a.put(1, "quick");
  17. a.put(2, "brown");
  18. a.put(3, "fox");
  19. a.put(4, "jumps");
  20. a.put(5, "over");
  21. a.put(6, "the");
  22. a.put(7, "lazy");
  23. a.put(8, "dog");
  24.  
  25. Map<Integer, String> b = new HashMap<>();
  26. b.put(1,"somewhere");
  27. b.put(2, "over");
  28. b.put(3, "the");
  29. b.put(4, "rainbow");
  30.  
  31. Set<String> bVal = new HashSet<String>(b.values());
  32. String[] res = a.values()
  33. .stream()
  34. .filter(s -> bVal.contains(s))
  35. .toArray(String[]::new);
  36. for (String s : res) {
  37. System.out.println(s);
  38. }
  39.  
  40.  
  41. }
  42. }
Success #stdin #stdout 0.2s 321856KB
stdin
Standard input is empty
stdout
over
the