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.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты