Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 7: ArrayList
Start Practice TestPractice Test
About Exam
easy Solved by 2 students

ArrayList Element Access

Mark
< Prev
Next >

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 incorrectly declares the ArrayList with type parameters.

B

It uses array index notation (items[0]) instead of the get method for ArrayLists.

C

It is missing the import statement for java.util.ArrayList.

D

It uses the add method with an incompatible argument.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|