Analyze the following code:

ArrayList list = new ArrayList();
list.add("Beijing");
list.add("Tokyo");
list.add("Shanghai");
list.set(3, "Hong Kong");

a. The last line in the code causes a runtime error because there is no element at index 3 in the array list.
b. The last line in the code has a compile error because there is no element at index 3 in the array list.
c. If you replace the last line by list.add(3, "Hong Kong"), the code will compile and run fine.
d. If you replace the last line by list.add(4, "Hong Kong"), the code will compile and run fine.

ac There is no element at index 3.

Computer Science & Information Technology

You might also like to view...

The ________ transition can be applied to add smooth animations between slides

Fill in the blank(s) with correct word

Computer Science & Information Technology

?Themap(callback [, thisArg])method returns the index of the first element in the array that passes a test in thecallbackfunction.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology