Code Template:
Map<String, String> hashMap = new HashMap<>();
hashMap.put("RED", "1");
hashMap.put("BLUE", "2");
hashMap.put("BLACK", "3");
Map<String, String> filteredMap = hashMap.entrySet().stream()
.filter(entry -> (entry.getKey().equals("RED") && entry.getValue().equals("1"))
**&&**
(entry.getKey().equals("BLUE") && entry.getValue().equals("2")) )
.collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue()));
I want to find if the Map contains both {Red,1} and {Blue,2} inside it. How do I put both filters condition in a stream? I tried with && condition, but it's not working. Kindly help.