java stream map,实现将对象list转为单属性list。
直接上代码。
List<String> collect = dataItemList.stream()
.map(item -> {
return item.getMobile();
})
.collect(Collectors.toList());
可见,通过return,可转换为各种类型的。
如写成
return new AAA(){...}
这样来控制类型。
如:
dataItemList.stream()
.map(item -> {
return new TempModel(...);
})
.collect(Collectors.toList());

List<String> collect = dataItemList.stream()
.map(item -> item.getMobile())
.collect(Collectors.toList());