1、把list集合转换成Map
①
List<OrgResponDetail>
oldDetails = new ArrayList();
Map<String,OrgResponDetail
> map = oldDetails.stream()
.collect(Collectors.toMap(temp -> temp.getId(), temp -> temp
));
②
Map<String,String> map = oldDetails.stream() .collect(Collectors.toMap(OrgResponDetail::getId,OrgResponDetail::getParentId
));
2、把list转换为list
List<String>
detailIds = list.stream()
.map
(temp -> temp.getId()).collect(Collectors.toList());
//filter方法里的条件是作为筛选条件
List<Scheduling>
resultList = list.stream()
.filter
(distinctByKey(temp -> temp.getOrgId())
).collect(Collectors.toList());
public static <T>
Predicate<T>
distinctByKey
(Function<? super T, Object> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
3、去重distinct()
List<String>
oldDetails = new ArrayList();
List<String>
list = list.stream().distinct()
.collect(Collectors.toList());
4、排序
//根据orders升序sorted方法
List itemVoList = list.stream().sorted(Comparator.comparing(DicGroupItemVo::getOrders))
.collect(Collectors.toList());