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.stream.*;
  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. Set<String> A_Set = new HashSet<>(Arrays.asList("1111", "2222", "5555"));
  14. Set<String> B_Set = new HashSet<>(Arrays.asList("3333", "4444"));
  15. Set<String> C_Set = new HashSet<>(Arrays.asList("6666"));
  16. Set<String> D_Set = new HashSet<>(Arrays.asList("2222", "5555", "6666"));
  17.  
  18. Map<String, Set<String>> values = new HashMap<>();
  19. values.put("A", A_Set);
  20. values.put("B", B_Set);
  21. values.put("C", C_Set);
  22. values.put("D", D_Set);
  23.  
  24. Map<String, List<Boolean>> exists = values.values()
  25. .stream()
  26. .flatMap(Set::stream)
  27. .distinct()
  28. .collect(Collectors.toMap(v -> v, v -> Stream.of("A", "B", "C", "D")
  29. .map(k -> values.get(k).contains(v))
  30. .collect(Collectors.toList())));
  31.  
  32. System.out.println(exists);
  33. }
  34. }
Success #stdin #stdout 0.15s 2184192KB
stdin
Standard input is empty
stdout
{3333=[false, true, false, false], 2222=[true, false, false, true], 1111=[true, false, false, false], 4444=[false, true, false, false], 5555=[true, false, false, true], 6666=[false, false, true, true]}