stream.filter
2021/11/24 6:10:35
本文主要是介绍stream.filter,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package com.mayikt.stream; import com.mayikt.entity.UserEntity; import java.util.ArrayList; import java.util.function.Predicate; import java.util.stream.Stream; /** * @ClassName Test14 * @Author 蚂蚁课堂余胜军 QQ644064779 www.mayikt.com * @Version V1.0 **/ public class Test14 { public static void main(String[] args) { ArrayList<UserEntity> userEntities = new ArrayList<>(); userEntities.add(new UserEntity("mayikt", 20)); userEntities.add(new UserEntity("meite", 28)); userEntities.add(new UserEntity("zhangsan", 35)); userEntities.add(new UserEntity("liusi", 21)); userEntities.add(new UserEntity("wangmazi", 19)); userEntities.add(new UserEntity("xiaoke", 19)); userEntities.add(new UserEntity("xiaoan", 21)); userEntities.add(new UserEntity("mayikt", 12)); // where userName='mayikt' and age>18 Stream<UserEntity> stream = userEntities.stream(); stream.filter(userEntity -> "mayikt".equals(userEntity.getUserName()) && userEntity.getAge() > 18) .forEach((userEntity -> System.out.println(userEntity))); } }
这篇关于stream.filter的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-27消息中间件底层原理资料详解
- 2024-11-27RocketMQ底层原理资料详解:新手入门教程
- 2024-11-27MQ底层原理资料详解:新手入门教程
- 2024-11-27MQ项目开发资料入门教程
- 2024-11-27RocketMQ源码资料详解:新手入门教程
- 2024-11-27本地多文件上传简易教程
- 2024-11-26消息中间件源码剖析教程
- 2024-11-26JAVA语音识别项目资料的收集与应用
- 2024-11-26Java语音识别项目资料:入门级教程与实战指南
- 2024-11-26SpringAI:Java 开发的智能新利器