I have to remove duplicated objects in a List. It is a List from the object Blog that looks like this:
public class Blog {
private String title;
priv
We can also use Comparator to check duplicate elements. Sample code is given below,
private boolean checkDuplicate(List studentDTOs){
Comparator studentCmp = ( obj1, obj2)
->{
if(obj1.getName().equalsIgnoreCase(obj2.getName())
&& obj1.getAddress().equalsIgnoreCase(obj2.getAddress())
&& obj1.getDateOfBrith().equals(obj2.getDateOfBrith())) {
return 0;
}
return 1;
};
Set setObj = new TreeSet<>(studentCmp);
setObj.addAll(studentDTOs);
return setObj.size()==studentDTOs.size();
}