I have an ArrayList of custom objects. I want to remove duplicate entries.
The objects have three fields: title, subtitle, and id. If a su
title, subtitle
id
List result = new ArrayList(); Set titles = new HashSet(); for(Item item : originalList) { if(titles.add(item.getTitle()) { result.add(item); } }
add() of the Set returns false if the element already exists.
add()
Set
false