Reputation: 1
I have a
List<Object> coins = exchange.getCoins();
I want to simplify the below code which is in java below 8.
if (coins != null && !coins.isEmpty()) {
//perform logic
}
The thing is that after the check I have lot of operation to perform, so I want to have a stream approach.
Upvotes: 0
Views: 703
Reputation: 76
Optional.ofNullable(coins).ifPresent(e->
e.stream()
.filter(x-> x.length()>0)
.map(...)
.collect(...))
Upvotes: 1
Reputation: 915
Just try use:
Stream.ofNullable(coins).filter(...).map(...).collect(..)
Upvotes: 1