Java8 新特性 Streams map() 示例

其实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());
郭慕荣博客园
原文地址:https://www.cnblogs.com/jelly12345/p/15095500.html