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.
Just try use:
Stream.ofNullable(coins).filter(...).map(...).collect(..)
Optional.ofNullable(coins).ifPresent(e-> e.stream() .filter(x-> x.length()>0) .map(...) .collect(...))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.