Using multiple map functions vs. a block statement in a map in a java stream

后端 未结 2 1104
囚心锁ツ
囚心锁ツ 2020-12-09 16:28

Say I have the following code

data.stream()
    .map(x -> {
        Object a = maybeReturnsNull(x);
        return a == null ? defaultValue : a;
    })
         


        
2条回答
  •  离开以前
    2020-12-09 17:15

    java has provided a dedicated API to handle with "null".

    https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html

提交回复
热议问题