ArrayList<Integer> a = new ArrayList<>();
a.add(1);
a.add(2);
a.add(3);
ArrayList<Integer> b = new ArrayList<>();
for (int x : a) b.add(x * 2);
System.out.println(b);What is printed?
- Acheck_circle
[2, 4, 6]
- B
[1, 2, 3]
- C
[1, 4, 9]
- D
[]
Explanation
Each element of a is doubled and added to b: 1<em>2=2, 2</em>2=4, 3*2=6.