How to make a new list with a property of an object which is in another list

前端 未结 6 1162
借酒劲吻你
借酒劲吻你 2020-12-22 16:49

Imagine that I have a list of certain objects:

List

And I need to generate another list including the ids of

6条回答
  •  悲哀的现实
    2020-12-22 17:22

    Java 8 lambda expression solution:

    List iDList = students.stream().map((student) -> student.getId()).collect(Collectors.toList());
    

提交回复
热议问题