java forEach循环list、获取list中的指定数据

博客主要围绕Java展开,介绍了使用forEach循环遍历List,以及获取List中指定数据的方法。如获取ListBean集合中特定actId的数据集合,还有去除两个List中name不同的数据等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

java forEach循环list、获取list中的指定数据

eg: List entityList = xxxx.getAllList();

1.forEach循环list

 entityList .forEach(
     listBean -> {
     	Integer id = listBean.getId();
     	Integer actId = listBean.getActId();
     	String name = listBean.getName(); //
     	listBean.setTitle("为title赋值新值");
     	......
       }
   )
   或
   for(ListBean listBean : b){
   		Integer id = b.getId();
     	Integer actId = b.getActId();
     	String name = b.getName(); //
     	b.setTitle("为title赋值新值");
   }

2.获取list中的指定数据

1.获取listBean集合中所有actId = x 的数据集合

List<Xxxx> firstListBeans = new ArrayList<>();
firstListBeans = listBean.stream().filter(vsList-> vsList.getActId() == x).collect(Collectors.toList());

2.去除entityLists1中与entityLists2中name不相同的值的数据

List<ListBean> entityLists1 = xxxx.getAllList();
List<ListBean> entityLists2 = xxxx.getList(name);
final List<ListBean>[] finalListBeans = new List[]{entityLists2 };
entityLists1 .forEach(entityList1 ->{
	finalListBeans[0] = finalListBeans[0].stream().filter(entityList2 -> entityList1.getName != entityList2.getName).collect(Collectors.toList());
});
//去除相同name值后的集合数据
List<ListBean> entityLists3 = finalListBeans[0];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值