Use Streams to return Boolean if all the List values in a Map are empty/not-empty

Stream::allMatch

In Java 8 you can check that not all lists are empty.

 boolean anyNonEmpty = !map.values().stream().allMatch(List::isEmpty);

Notice that Stream::allMatch is a short-circuiting terminal operation. So the stream is efficient, not running any longer than need be.


Use the anyMatch method that finds if any element of the stream matches a Predicate. Here, your predicate is that the entry's value (the list) is not empty.

boolean anyNonEmpty = map.entrySet()
    .stream()
    .anyMatch(entry -> !entry.getValue().isEmpty());