//获取user里面所有id集合 List<String> idList = list.stream().map(User::getId).collect(Collectors.toList()); //list转换为id为key的map Map<String, User> userMap = list.stream().collect(Collectors.toMap(User::getId, a -> a,(k1,k2)->k1));
//list转换为type为key的分类mapList Map<String, User> userMap = list.stream().collect(Collectors.groupingBy(User::getType));
//list转换为数组
list.stream().toArray(String[]::new);
stream的方法
Collectors的静态方法
标签:java,stream,Collectors,list,collect,User,集合,id
From: https://www.cnblogs.com/uip001/p/14741362.html