Check if all values of a map are true
0
I have one Map<String, Boolean> map = new HashMap<>();
.
Consider there are five keys in it.
map.put("A", true);
map.put("B", true);
map.put("C", false);
map.put("D", true);
map.put("E", true);
I need to set one boolean flag as true if all the values in the above map are true.
If any value is false then i need to set boolean flag as false
I can iterate this map and do it like old ways but i want to know how can i do this in a single line by streaming on this map.
java java-8 hashmap java-stream
!map.containsValue(false)
, not to write a loop. So for this specific task, using the Stream API is not an improvement. – Holger Apr 28 at 7:29