ArrayList<Integer> a = new ArrayList<>();
a.add(1);
a.add(2);
ArrayList<Integer> b = new ArrayList<>();
for (int x : a) b.add(x);
b.add(99);
System.out.println(a.size() + " " + b.size());What is printed?
- Acheck_circle
2 3
- B
1 2
- C
2 2
- D
3 3
Explanation
b is a separate ArrayList copy, so adding to b does not affect a. Sizes are 2 and 3.