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];
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐