The java8 implementation extracts each property of the collection object

  • 2021-08-16 23:54:33
  • OfStack

Create a new collection


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

Extract the names of all items in the order to make a collection


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

Additional: java8 lamada extracts the properties of each object in the collection

In the China-Taiwan project:


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

Baidu's:


List students = new ArrayList();

After inserting an object into list,


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

Related articles: