其实map主要是操作集合中的每一个元素
1.对象列表 - >字符串列表

List<String> collect = staff.stream().map(x -> x.getName()).collect(Collectors.toList());

2.对象列表 - >其他对象列表

List<StaffPublic> result = staff.stream().map(temp -> {
StaffPublic obj = new StaffPublic();
obj.setName(temp.getName());
obj.setAge(temp.getAge());
if ("mkyong".equals(temp.getName())) {
obj.setExtra("this field is for mkyong only!");
}
return obj;
}).collect(Collectors.toList());

 

相关文章:

  • 2021-08-25
  • 2021-12-11
猜你喜欢
  • 2022-12-23
  • 2021-10-05
  • 2022-12-23
  • 2021-06-06
  • 2021-07-24
相关资源
相似解决方案