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.

Share
Improve this question
1
  • 2
    “The old way” would be !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

Comments

Popular posts from this blog

Meaning of `{}` for return expression

Get current scroll position of ScrollView in React Native

flutter websocket connection issue