1. 获取对象字段的列表
List idcards= users.stream().map(User::getIdcard).collect(Collectors.toList());
2. 构建列表
List list = fileNames.stream().map(i ->
{
Enclosure enclosure = new Enclosure();
enclosure.setName(i);
enclosure.setUploadTime(new Timestamp(System.currentTimeMillis()));参数错误
enclosure.setPath("testurl" + i);
return enclosure;
}).collect(Collectors.toList());
3. list转map
Map map = users.stream().collect(Collectors.toMap(User::getName, User::getAge));
Map map = users.stream().collect(Collectors.toMap(User::getName, Function.identity()));Map resMap=map.entrySet().stream().collect(Collectors.toMap( entry1 -> entry1.getKey(),entry2 -> entry2.getValue()));
4. 转map时key重复怎么处理
Collectors.toMap(dto->key值,dto->dt
jdk8 Lambda,stream,juc 新特性
最新推荐文章于 2022-11-14 19:30:40 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)