Java8:如何根据保留顺序的多个属性从列表中删除重复项

我正在尝试从基于多个属性的学生对象列表中删除重复项,同时保留顺序,如下所示,我有学生对象列表,其中我们有多个同名但出席率不同的学生......我需要删除重复项具有相同名称且学生出席人数为 100 的学生,同时保留顺序。

Student{studentId=1, studentName='Sam', studentAttendence=100, studentAddress='New York'}
Student{studentId=2, studentName='Sam', studentAttendence=50, studentAddress='New York'}
Student{studentId=3, studentName='Sam', studentAttendence=60, studentAddress='New York'}
Student{studentId=4, studentName='Nathan', studentAttendence=40, studentAddress='LA'}
Student{studentId=5, studentName='Ronan', studentAttendence=100, studentAddress='Atlanta'}
Student{studentId=6, studentName='Nathan', studentAttendence=100, studentAddress='LA'}

删除重复项后的愿望输出:

Student{studentId=2, studentName='Sam', studentAttendence=50, studentAddress='New York'}
Student{studentId=3, studentName='Sam', studentAttendence=60, studentAddress='New York'}
Student{studentId=4, studentName='Nathan', studentAttendence=40, studentAddress='LA'}
Student{studentId=5, studentName='Ronan', studentAttendence=100, studentAddress='Atlanta'}

我现在所拥有的只是根据名称删除重复项而不考虑百分比(100)......并且也不保留订单......非常感谢任何帮助。(学生供应商是学生名单的简单供应商功能)

studentsSupplier.get().stream()
                .sorted(Comparator.comparing(Student::getStudentName))
                .collect(Collectors.collectingAndThen(
                        Collectors.toCollection(
                                () -> new TreeSet<>(Comparator.comparing(Student::getStudentName))), ArrayList::new));

注意:只有学生姓名匹配且百分比为100的重复记录必须删除,(记录Ronon有百分比100但没有重复的学生姓名相同,因此不能删除)

以上是Java8:如何根据保留顺序的多个属性从列表中删除重复项的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>