A collection without duplicates (how to determine duplicates being up to you) is a Set
.
A collection that maintain an arbitrary order is a List (in ArrayList the default order is the order of insertion). Note that list MAINTAIN an order ... but does not necessarily sort its elements.
Anyway if you want to keep the insertion order AND keep out duplicates you can use a LinkedHashSet<>
.
In your case you need to reimplement the equals(~)
and hashCode()
functions of your ExpAdminBean class if possible. I suggest you implement it so that equals returns true when nroDocumento is equal and return the hashCode of nroDocumento dirrectly in the new hashCode implementation.
Otherwize if you cannot do that I suggest you use a map:
Map<String, ExpAdminBean> map = ~~~~~~ ;
for(ExpAdminBean exp : listaExpAdminAux) {
if(!map.containsKey(exp.getNroDocumento())
map.put(exp.getNroDocumento(), exp);
}
//if you need to put the values in a list you can do ...
ArrayList<ExpAdminBean> theList = new ArrayList<>(map.size());
theList.addAll(map.values());
Like I said before if you want to keep the "insertion order" of your first list you should use a LinkedHashMap<>
or a LinkedHashSet<>
.