ArrayList<Integer> a = new ArrayList<>();
a.add(1);
a.add(2);
ArrayList<Integer> b = a;
b.add(3);
System.out.println(a.size());What is printed?
- Acheck_circle
3
- B
2
- C
1
- D
4
Explanation
b and a refer to the same ArrayList object. Adding through b also affects a, so size becomes 3.