根据Handover_record_id去除List<HandoverRecordList>中重复的对象
传统的去重方法:
public static List<HandoverRecordList> removeDuplicate(List<HandoverRecordList> list)
{
for (int i = 0; i < list.size() - 1; i++)
{
for (int j = list.size() - 1; j > i; j--)
{
if (list.get(j).getHandover_record_id()== (list.get(i).getHandover_record_id()))
{
list.remove(j);
}
}
}
return list;
}
java8去重:
//handoverRecordLists就是List
handoverRecordLists=handoverRecordLists.stream().collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(HandoverRecordList::getHandover_record_id))), ArrayList::new)
);