JDK1.8去重


1、按照对象中的一个或多个属性去重

List clientGatherList= BeanConvertUtil.convertList(postRealtimeVisitClientInput.getClientData(), Clientgather.class);

// 根据client_id 数据去重
clientGatherList = clientGatherList.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(o -> o.getClientId() ))),
ArrayList::new));

 

// 根据client_id 和 fund_account对数据去重

clientGatherList = clientGatherList.stream().collect(Collectors.collectingAndThen(
Collectors.toCollection(
() -> new TreeSet<>(Comparator.comparing(o -> o.getClientId() + “;” + o.getFundAccount()))),
ArrayList::new));

 

posted @ 2022-10-12 09:18  不该懂的还是懂了  阅读(749)  评论(0)    收藏  举报