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

ArrayList in AP Computer Science A

Question 1
college-boardComputer Science AAPExam Style
1 mark

How do you determine the number of elements currently stored in an ArrayList named "myList"?

Question 2
college-boardComputer Science AAPExam Style
1 mark

What does the following code do?

public static ArrayList codeBlock(int[] array) { ArrayList newArray = new ArrayList(); for (int i: array) { newArray.add(i); } return newArray; }

Question 3
college-boardComputer Science AAPExam Style
1 mark

When should you use a while loop over a traditional for loop while working with an ArrayList?

Question 4
college-boardComputer Science AAPExam Style
1 mark

Which method is commonly used to add an element to an ArrayList in Java?

Question 5
college-boardComputer Science AAPExam Style
1 mark

How would one efficiently append all elements from one ArrayList listA into another listB ensuring that no duplicates are added to listB?

Question 6
college-boardComputer Science AAPExam Style
1 mark

In order to replace every instance of 'apple' with 'orange' in an ArrayList fruits, which approach would correctly accomplish this task?

Question 7
college-boardComputer Science AAPExam Style
1 mark

Which method signature would correctly allow an algorithm that uses ArrayLists to handle exceptions when items are added incorrectly?

Feedback stars icon

How are we doing?

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

Question 8
college-boardComputer Science AAPExam Style
1 mark

What code would replace "item" from position "index" in an existing ArrayList called "records"?

Question 9
college-boardComputer Science AAPExam Style
1 mark

What would be the best reason to use an ArrayList over an array when developing an algorithm?

Question 10
college-boardComputer Science AAPExam Style
1 mark

What is returned by the following code if the passed in ArrayList is [6, 5, 5, 2, 8]?

public static int codeBlock(ArrayList array) { int x = 0; int y = 0; for (int i = 0; i < array.size() - 1; i++) { int z = 1; for (int j = i + 1; j < array.size(); j++) { if (array.get(j) == array.get(i))...