Question: What will the following program print when compiled and run? Select the one correct answer. (a) The program will not compile. (b) The program will
What will the following program print when compiled and run?

Select the one correct answer.
(a) The program will not compile.
(b) The program will throw an IndexOutOfBoundsException at runtime.
(c) The program will throw a NullPointerException at runtime.
(d) The program will throw a ConcurrentModificationException at runtime.
(e) The program will not terminate when run.
(f) The program will print [Anna, Ada, Bob].
(g) The program will print [Anna, Ada].
import java.util.ArrayList; import java.util.List; public class RQ12A30 { public static void main(String [] args) { List strList = new ArrayList (); strList.add ("Anna"); strList.add("Ada"); strList.add ("Bob"); strList.add ("Bob"); for (int i= 0; i < strList.size(); ++i) { if (strList.get (i) .equals ("Bob")) { strList.remove (i); 4 } } } System.out.println (strList);
Step by Step Solution
3.37 Rating (141 Votes )
There are 3 Steps involved in it
f Deleting elements when traversing a list requires care as the size chang... View full answer
Get step-by-step solutions from verified subject matter experts
