Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return false if any of the values in map is empty string or just blanks in java8

I am trying to write one-liner code that will return false if any of the values in the map is empty string or string of blanks. Thoughts?

Something like a advanced version of:

 Optional.ofNullable(map).filter(s -> s.isEmpty());
like image 642
Andy897 Avatar asked Dec 24 '22 11:12

Andy897


1 Answers

using your current approach:

boolean present = 
        Optional.ofNullable(map)
                .filter(x -> 
                        x.values().stream()
                                  .noneMatch(s -> s != null && s.trim().isEmpty()))
                                  .isPresent();

or simply:

boolean present = map != null && 
                  map.values()
                     .stream()
                     .noneMatch(s -> s != null && s.trim().isEmpty());
like image 54
Ousmane D. Avatar answered Jan 14 '23 04:01

Ousmane D.