简体   繁体   English

列表中的Java流 <Object> 获取任何与filter()匹配的对象的属性

[英]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.

相关问题 具有任何匹配属性的 JAVA 8 过滤器列表 - JAVA 8 filter list of object with any matching property Java 8 个流 - 按 object 的属性过滤 - Java 8 Streams - filter by a property of an object 使用 java 8 流过滤和修改列表对象 - Filter and modify list object using java 8 streams 获取列表中具有Java中特定匹配属性的对象数 - Get number of object in a List with specific matching property in Java 过滤器 Map <string,list<object> &gt; 使用 Java 流</string,list<object> - Filter Map<String,List<Object>> Using Java Streams 使用 java-streams 过滤 - 查找具有匹配属性嵌套在另一个对象中的对象的出现 - Filtering with java-streams - Find an occurrence of the Object with the matching property Nested inside Another Object Java8流:从两个命令对象列表中过滤数据。 我还在做什么其他有效的方式? - Java8 streams : Filter data from two list of command object. Is there any other efficient way of what i am doing? 取得清单 <String> 和HashMap <String, Object> 使用Java 8流 - Get List<String> and HashMap<String, Object> using Java 8 streams Java 8流-如何过滤列表并获取值 - Java 8 streams - how to filter a list and get a value 在Java中从Object List动态获取Object的属性列表 - Get the list of property of Object from List of Object dynamically in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM