I have an ArrayList
, and I want to remove repeated strings from it. How can I do this?
you can use nested loop in follow :
ArrayList l1 = new ArrayList();
ArrayList l2 = new ArrayList();
Iterator iterator1 = l1.iterator();
boolean repeated = false;
while (iterator1.hasNext())
{
Class1 c1 = (Class1) iterator1.next();
for (Class1 _c: l2) {
if(_c.getId() == c1.getId())
repeated = true;
}
if(!repeated)
l2.add(c1);
}