1 Java获取List对象的某属性组成新的List
List<String> list = signPicsDtoEntityList.stream().map(e->e.getType()).collect(Collectors.toList());
2 Java批量修改List里面某个属性的方法
方法一:通过流的方式
List<DishFlavor> flavors = dishDto.getFlavors(); flavors = flavors.stream().map((item) -> { item.setDishId(dishId); return item; }).collect(Collectors.toList());
方法二:通过forEach
List<DishFlavor> dishList;
dishList.forEach(item -> {
if (item.getExam_res_start_time().compareTo(oldIBay.getTime_slice_end_time()) >= 0 && item.getExam_res_end_time().compareTo(newTimeSliceEndTimeCur) <= 0) {
item.setExam_res_statues(DvResourceConstants.EXAM_RES_STATUES.YSC);
} else {
item.setExam_res_statues(item.getExam_res_statues());
item.setExam_res_start_time(newTimeSliceEndTimeCur);
}
});
原文链接:https://blog.csdn.net/weixin_49628243/article/details/124669398
3 关于List的方法removeif()的使用
List<DishFlavor> dishList;
dishList.removeIf(k -> DvResourceConstants.EXAM_RES_STATUES.YSC.equals(k.getExam_res_statues()));
原文链接:https://blog.csdn.net/zhang19age_/article/details/125646734
4 通过Java列表中的属性获取对象的索引
int index = IntStream.range(0, timeSlicePans.size()).filter(i -> timeSlicePans.get(i).getTime_slice_id() .equals(closeTimeSliceId)).findFirst().orElse(-1);
原文链接:https://www.imooc.com/wenda/detail/671687(
标签:statues,dishList,res,List,特性,item,getExam,Java8 From: https://www.cnblogs.com/daytoy105/p/17452491.html