Java中给List 对象集合去重
java
List<Student> getStudentList = studentMapper.getStudentList();
List<Student> distinctInsurance = distinctByField(getStudentList, Student::getCertNo);
java
public static <T> List<T> distinctByField(List<T> list, Function<T, Object> fieldExtractor) {
Set<Object> seen = new HashSet<>();
return list.stream()
.filter(item -> seen.add(fieldExtractor.apply(item)))
.collect(Collectors.toList());
}