I know there is a lot of question related to this exception. Even I also asked this question before Getting ConcurrentException when working with list and solution was use ListIterator
instead of iterator. In my below program I have used ListIterator
but still I got this exception.
I am really not able to understand why I got this exception. Can any one help me to sort this out?
public static void main(String args[]) {
List<String> myList = new ArrayList<String>();
myList.add("1");
myList.add("2");
myList.add("3");
myList.add("4");
myList.add("5");
List<String> myList_1 = new ArrayList<String>();
myList_1.add("4");
myList_1.add("6");
ListIterator<String> it = myList.listIterator();
mainLoop:
while(it.hasNext()) {
String internalAperture = it.next();
System.out.println("Aperture:"+internalAperture);
String refreneceNumber = internalAperture;
if (refreneceNumber.equals("6")) {
myList.add("6");
break;
}
else {
ListIterator<String> it_ = myList_1.listIterator();
while(it_.hasNext()) {
String a = it_.next();
myList.add(a);
continue mainLoop;
}
}
}
}