ArrayList<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
System.out.println(list.get(2));What is the result?
- Acheck_circle
IndexOutOfBoundsException
- B
null
- C
0
- D
Compile-time error
Explanation
Valid indices are 0 and 1 only. Accessing index 2 throws IndexOutOfBoundsException at runtime.