去重
List<BhFxTzz> collect = dwFx.getTzzList()
.stream()
.distinct()
.collect(Collectors.toList());
自定义去重
//去重方法
private static <T> Predicate<T>
distinctByKey(Function<? super T, ?> keyExtractor) {
Set<Object> seen = ConcurrentHashMap.newKeySet();
return t -> seen.add(keyExtractor.apply(t));
}
//stream 中引用
List<BhFxTzz> distinctTzzList = list
.stream()
.filter(distinctByKey(BhFxTzz::getTsj))
.collect(Collectors.toList());
排序
List<TestEntity> list=new LinkedList<>();
//默认正序
List<TestEntity> collect = list.stream()
.sorted(Comparator.comparing(TestEntity::getSj))
.collect(Collectors.toList());
//倒叙的情况(Comparater.reverseOrder)
List<TestEntity> collect = list.stream()
.sorted(Comparator.comparing(TestEntity::getSj,Comparator.reverseOrder()))
.collect(Collectors.toList());
过滤
List<Instruct> sendList = list
.stream()
.filter(a -> a.getSrc().equals(domain.getUid())
&& a.getType1().equals(domain.getType1()))
.collect(Collectors.toList());