Get list of attributes of an object in an List

前端 未结 8 1735
青春惊慌失措
青春惊慌失措 2020-12-12 19:12

When there is an List, is there a possibility of getting List of all person.getName() out of that? Is there an prepared call for that

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 19:26

    You might have done this but for others

    using Java 1.8

    List namesList = personList.stream().map(p -> p.getName()).collect(Collectors.toList()); 
    

提交回复
热议问题