使用场景:
利用集合A中的元素(我是为了取属性值),生成一个新的集合B,两个集合的元素类型可以不一样。
org.springframework.data.domain.Page:
Page<T> targetPage = sourcePage.map(variable -> {
//生成新类型对象
T variable2 = new T();
//转换操作,比如复制属性值
BeanUtils.copyProperties(variable, variable2);
variable2.setCreateTime(new Date());
variable2.setUpdateTime(new Date());
//返回新类型对象
return archiveVo2;
});
java.util.List:
List<T> targetList = sourceList.stream().map(sourceVariable -> {
//生成新类型对象
T targetVariable = new T();
BeanUtils.copyProperties(sourceVariable , targetVariable);
return targetVariable ;
}).collect(Collectors.toList());
其他集合类型待补充。。。