java8,去重复

时间:2021-04-27 15:06:52   收藏:0   阅读:0

 

1.对多个字段去重复

	ArrayList<SupplierDeliveryCountNum> collect = numlist.stream()
							.collect(Collectors.collectingAndThen(
									Collectors.toCollection(() -> new TreeSet<>(
											Comparator.comparing(o -> o.getDeliveryId() + ";" + o.getNum()))),
									ArrayList::new));

  

 

2. 对全部字段去重复

List<SupplierDeliveryCountNum> distinctIdList = numlist.stream().distinct()
							.collect(Collectors.toList());

  

 

 

 

 

 

.

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!