When processing large amounts of data I often find myself doing the following:
HashSet set = new HashSet ();
//Adding elements to
If you don't need a list, I would just use a Set and this is the natural collection to use if order doesn't matter and you want to ignore duplicates.
You can do both is you need a List without duplicates.
private Set set = new HashSet<>();
private List list = new ArrayList<>();
public void add(String str) {
if (set.add(str))
list.add(str);
}
This way the list will only contain unique values, the original insertion order is preserved and the operation is O(1).