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.

a. The last line in the code causes a runtime 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.

Computer Science & Information Technology

You might also like to view...

Certificates are issued by trusted companies that are known as certification ________

Fill in the blank(s) with correct word

Computer Science & Information Technology

Risk analysis is the same activity as risk management.

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

Computer Science & Information Technology