zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank
GlossaryGlossary

ArrayList in AP Computer Science A

Question 1
Computer Science AAPConcept Practice
1 mark

Which of the following is the correct way to instantiate an ArrayList that holds Integer objects?

Question 2
Computer Science AAPConcept Practice
1 mark

What is the purpose of the size() method in the ArrayList class?

Question 3
Computer Science AAPConcept Practice
1 mark

Given an ArrayList<String> called names, what will be the output of names.size() after the following operations? names.add("Alice"); names.add("Bob"); names.remove(0);

Question 4
Computer Science AAPConcept Practice
1 mark

Consider the following code snippet:

java
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(10);
numbers.add(20);
numbers.add(30);
numbers.set(1, 40);
numbers.remove(0);
System.out.println(numbers.get(1));

What will be printed to the console?

Question 5
Computer Science AAPConcept Practice
1 mark

Which of the following loops is the correct way to iterate through an ArrayList<String> called names and print each name?

Question 6
Computer Science AAPConcept Practice
1 mark

When is it NOT appropriate to use a for-each loop to traverse an ArrayList?

Question 7
Computer Science AAPConcept Practice
1 mark

What happens when you attempt to modify the size of an ArrayList (e.g., adding or removing elements) while traversing it using a for-each loop?

Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
Computer Science AAPConcept Practice
1 mark

Which of the following code snippets correctly converts an ArrayList<Integer> called list to an Integer[] array?

Question 9
Computer Science AAPConcept Practice
1 mark

What is the primary ethical concern related to the collection of user data using ArrayLists or other data structures?

Question 10
Computer Science AAPConcept Practice
1 mark

Why is encryption important when handling personal data?