-
获取list对象中的指定字段 List<Long> userId= scheduleStudents.stream().map(User::getUserId).collect(Collectors.toList()); List<Long> ids = list.stream().map(u-> u.getUserId()).collect(Collectors.toList());
- string转list<String>
List<String> idList = Arrays.asList(componentRelate.getIds().split(",")); - string转list<Long>
List<Long> idList = Arrays.asList(componentRelate.getIds().split(",")) .stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList()); - 对象互转
List<CourseScheduleBase> finishCourse = finishCourseSchedules.stream().map(a->{ return getScheduleBase(a); }).collect(Collectors.toList());// 将 List<Category> 转换为 List<CategoryChildModel> List<CategoryChildModel> categoryChildModelList = categoryList.stream() .map(category -> { CategoryChildModel childModel = new CategoryChildModel(); BeanUtils.copyProperties(category,childModel); return childModel; }) .collect(Collectors.toList());
stream灵活应用,list和String互转
于 2022-03-25 10:52:51 首次发布
本文介绍如何使用 Java Stream API 来获取 List 对象中的指定字段,包括将字符串转换为 List 对象的过程。通过实例展示了 Stream API 的强大功能,如 map 和 collect 方法的应用。
4016

被折叠的 条评论
为什么被折叠?



