2
Hello I have an arrayList of objects. however these objects end up repeating themselves, so I wanted a naneira to remove duplicates.
I’ve tried using Hasset, but it doesn’t seem to work with objects.
Set nova = new HashSet<>();
nova.addAll(Objetos);
Objetos.clear();
Objetos.addAll(nova);
I’ve tried to use an if comparison but it didn’t work either.
List<T> naoDuplicado = new ArrayList<T>();
for (T obj : naoDuplicado) {
if (!naoDuplicado.contains(Obj)) {
naoDuplicado.add(element);
}
}