I want to compare the first element of list with all the consecutive elements and increment the first character and then compare again.
if elements have the same character then i remove the second occurance of the element
al =["a1","a","1a","ab"]
a1 and 1a have the same characters and i want to remove 1a
a1 = ["a1","a","ab"]
This is the code i've written to iter through the elements
while(iter.hasNext()){
current = iter.next();
while(iter.hasNext())
{
String next = iter.next();
if(check(current,next))
a.remove(next);
}
}
On implementing this i get this error
Exception in thread "main"
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(Unknown Source)
at java.util.ArrayList$Itr.next(Unknown Source)
at anasub.ana(anasub.java:51)
at anasub.main(anasub.java:81)
I tried using a for loop but when i remove the element inside the loop I get ArrayIndexOutOfBound exception.
Please review this code or provide an alternate solution.