当前位置:主页 > 软件编程 > JAVA代码 >

java8 实现提取集合对象的每个属性

时间:2021-12-15 09:13:44 | 栏目:JAVA代码 | 点击:

新建一个集合

List<Bill> billList = new ArrayList<>();

将订单中所有物品的名称提取出来做一个集合

List<String> goodsNameList = billList.stream().map(Bill::getGoodsName).collect(Collectors.toList());

补充:java8 lamada 提取集合中每个对象的属性

中台项目中:

MelotPageResult questionRelas = questionStudentRelaBiz.queryByParam(param);
List questionIds = questionRelas.getList().stream().map(QuestionStudentRela::getQuestionId).collect(Collectors.toList());

百度的:

List students = new ArrayList();

往list里插入对象后

List names =students.stream().map(Student::getName).collect(Collectors.toList());

您可能感兴趣的文章:

相关文章