An intersection of Two Lists Objects in java 8. Can some tell me what am I doing wrong?
List originalStudent = new ArrayList<>();
List&l
What you can do is construct a SortedSet from the two concatenated lists originalStudent and newStudent. The sorted set uses a Comparator.comparing(Student::getName).thenComparing(Student::getLastName) as its comparator.
Stream.concat(originalStudent.stream(), newStudent.stream())
.collect(Collectors.toCollection(() -> new TreeSet<>(
Comparator.comparing(Student::getFname)
.thenComparing(Student::getLname))
))