ArrayList<Integer> a = new ArrayList<>();
a.add(1);
a.add(2);
a.add(3);
ArrayList<Integer> b = new ArrayList<>();
for (int i = a.size() - 1; i >= 0; i--) b.add(a.get(i));
System.out.println(b);What is printed?
- A
[]
- B
[1, 2, 3]
- Ccheck_circle
[3, 2, 1]
- D
[3, 2, 1, 0]
Explanation
Iterating from the last index to 0 and appending to b reverses the list.