ArrayList<String> list = new ArrayList<>();
list.add("x");
list.add("y");
list.add("z");
System.out.println(list.get(list.size() - 1));What is printed?
- A
Index out of bounds
- B
x
- C
y
- Dcheck_circle
z
Explanation
list.size() is 3, so list.size() - 1 = 2, which is the last index. The element is "z".