ArrayList Element Access
Why does the following code fail to compile?
import java.util.ArrayList;
public class WrongAccess {
public static void main(String[] args) {
ArrayList<String> items = new ArrayList<>();
items.add("First");
System.out.println(items[0]);
}
}
A
It is missing the import statement for java.util.ArrayList.
B
It incorrectly declares the ArrayList with type parameters.
C
It uses the add method with an incompatible argument.
D
It uses array index notation (items[0]) instead of the get method for ArrayLists.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE