ArrayList<String> list = new ArrayList<>();
list.add("A");
list.add("B");
list.add("C");
list.add(1, "X");
System.out.println(list);What is printed?
- A
[A, X, C]
- B
[X, A, B, C]
- C
[A, B, X, C]
- Dcheck_circle
[A, X, B, C]
Explanation
add(1, "X") inserts "X" at index 1, shifting "B" and "C" to the right. The result is [A, X, B, C].