I want to merge two ArrayList of objects without duplicate records using Java 8. I can not modify hashcode and equals method of a class, but I can identify duplicate using class parameters.
Pseudo Code
public class Students {
int id; // Use to identify duplicates
String name;
//getters , setters and constructor code
}
public class Start {
public static void main(String[] args) {
List<Students> list1= new ArrayList<>();
list1.add( new Students(1,"Josh"));
list1.add( new Students(2, "Jacob"));
list1.add(new Students(3,"Jane"));
List<Students> list2= new ArrayList<>();
list2.add( new Students(1, "Josh"));
list2.add(new Students(4,"Jorge"));
// merge two list without duplicate
Stream.of(list1,list2).flatMap(List :: Stream ) // now how can I filter duplicates ?
}
}