Q. What will be the output of the following code –

Code:
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public class CopyOnWriteArrayListTest
{
public static void main (String args[])
{
List<String> copyOnWriteArrayList = new CopyOnWriteArrayList<String>();
copyOnWriteArrayList.add(” Ind “);
copyOnWriteArrayList.add(” usa “);
copyOnWriteArrayList.add(null);
for(String string : copyOnWriteArrayList)
{
System.out.print(string+””);
copyOnWriteArrayList.add(“newEle3”) ;
}
}
}
  • (A) ind followed by NullPointerException
  • (B) ind followed by ConcurrentModificationException
  • (C) ind usa null
  • (D) Compile time exception
πŸ’¬ Discuss
βœ… Correct Answer: (C) ind usa null

You must be Logged in to update hint/solution

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
205
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Uday Singh
Publisher
πŸ“ˆ
94%
Success Rate