我有一个
List<Object> coins = exchange.getCoins();
我想简化下面的代码,这是在java低于8。
if (coins != null && !coins.isEmpty()) {
//perform logic
}问题是,在检查之后,我有很多操作要执行,所以我想使用流方法。
发布于 2020-06-05 16:18:05
只需尝试使用:
Stream.ofNullable(coins).filter(...).map(...).collect(..)发布于 2020-06-05 17:35:56
Optional.ofNullable(coins).ifPresent(e->
e.stream()
.filter(x-> x.length()>0)
.map(...)
.collect(...))https://stackoverflow.com/questions/62210651
复制相似问题