[英]Java streams on List<Object> get a property of any object matching filter()
I want to get the property of any object matching the filter() of the stream, but I am unable to. 我想获取与流的filter()匹配的任何对象的属性,但是我无法做到。
transactionsList.stream()
.filter(transaction -> transaction.getPayerIban() != null)
.findFirst()
//Here I get an Optional<Object>
.ifPresent()
.map(Transaction::getName)
I don't know what to do inside the .ifPresent()
stream operation, but I want to get any transaction name of the matching transactions 我不知道在.ifPresent()
流操作中做什么,但是我想获取匹配事务的任何事务名称。
Remove the ifPresent()
: 删除ifPresent()
:
Optional<String> optionalName = transactionsList.stream()
.filter(transaction -> transaction.getPayerIban() != null)
.findFirst()
.map(Transaction::getName);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.