fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.Arrays;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.function.Function;
  8. import java.util.stream.Collectors;
  9. import java.util.stream.IntStream;
  10. import java.util.stream.Stream;
  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<Map<String, String>> customerDirectory = List.of(
  18. Map.of("NAME", "a", "PHONE", "123", "ADDRESS", "dd"),
  19. Map.of("NAME", "c", "PHONE", "34534", "ADDRESS", "ddd"),
  20. Map.of("NAME", "b", "PHONE", "3454", "ADDRESS", "tt"));
  21. Map<String, String> customerInfo = new HashMap<>();
  22. customerInfo.put("NAME", "a");
  23. customerInfo.put("PHONE", "123");
  24. customerInfo.put("ADDRESS", null);
  25.  
  26. List<String> compareKeys = Arrays.asList("NAME", "PHONE", "ADDRESS");
  27.  
  28. boolean anyMatch =
  29. customerDirectory.stream()
  30. .anyMatch(m -> compareKeys.stream()
  31. .allMatch(key -> m.get(key).equals(customerInfo.get(key))));
  32.  
  33. System.out.println(anyMatch);
  34. }
  35. }
Success #stdin #stdout 0.07s 34024KB
stdin
Standard input is empty
stdout
false