Java 8 Stream String Null Or Empty Filter

前端 未结 6 2052
你的背包
你的背包 2021-01-01 09:34

I\'ve got Google Guava inside Stream:

this.map.entrySet().stream()
.filter(entity -> !Strings.isNullOrEmpty(entity.getValue()))
.map(obj -> String.form         


        
6条回答
  •  执念已碎
    2021-01-01 10:32

    You can create your own Strings class with your own predicate:

    public class Strings {
      public static boolean isNotNullOrEmpty (String str) {
        return str != null && !str.isEmpty();
      }
    }
    

    Then in your code:

    .filter(Strings::isNotNullOrEmpty)
    

    But as @fge mentionned, you can't use that on a Map.Entry...

提交回复
热议问题