CompareList.stream().filter
时间: 2024-04-17 12:22:31 浏览: 157
CompareList.stream().filter方法是用于在一个列表中过滤出符合某些条件的元素。根据提供的引用内容,有两种使用方式可以实现这个功能。
1. 使用Lambda表达式过滤条件[^1]:
```java
List<User> filteredList = CompareList.stream()
.filter(a -> !a.getJobNumber().equals("201901"))
.collect(Collectors.toList());
```
这个例子中,我们使用Lambda表达式`a -> !a.getJobNumber().equals("201901")`作为过滤条件,过滤掉了`jobNumber`不等于"201901"的元素,并将过滤后的结果收集到一个新的列表中。
2. 使用方法引用过滤条件:
```java
List<Date> filteredList = CompareList.stream()
.map(User::getEntryDate)
.filter(Objects::nonNull)
.collect(Collectors.toList());
```
这个例子中,我们使用方法引用`User::getEntryDate`将`CompareList`中的每个元素映射为`entryDate`属性的值,然后使用`filter`方法过滤掉`entryDate`为`null`的元素,并将过滤后的结果收集到一个新的列表中。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![md](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)