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
use this code
public List removeDuplicates(List list) {
// Set set1 = new LinkedHashSet(list);
Set set = new TreeSet(new Comparator() {
@Override
public int compare(Object o1, Object o2) {
if (((Blog) o1).get().equalsIgnoreCase(((Blog) o2).getId()) /*&&
((Blog)o1).getName().equalsIgnoreCase(((Blog)o2).getName())*/) {
return 0;
}
return 1;
}
});
set.addAll(list);
final List newList = new ArrayList(set);
return newList;
}