What will happen if you attempt to compile and run the following code:

import java.util.*;
class Quizful {
  public static void main(String[] args) {
     List<String> arrayList = new ArrayList<String> (); 
     arrayList.add("One"); 
     arrayList.add("Two"); 
     arrayList.add("Three"); 
          
     for (Iterator<String> iter = arrayList.iterator(); iter.hasNext();) { 
         String current = iter.next(); 
         if (current.length() == 3) { 
             arrayList.remove(current); 
         } 
     } 
          
     for (String current:arrayList) 
         System.out.println(current); 
  }
}
Explanation
The list is modified directly while iterating over it is still in progress. The situation is treated as concurrent modification while such modification is not permissible.

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Cosmo
Sign Up Now
or Subscribe for future quizzes