Verityprep
Question Bank · Unit 4

AP® Computer Science A Data Collections Multiple Choice Questions

Work through AP Computer Science A multiple-choice questions on Data Collections, then check each answer against a worked solution.

Free · no sign-up Open questions need no account. Sign up or log in to open the rest.

Subtopic: Arraylists Clear filter

Questions 151–160 of 173
  1. 151
  2. 152
  3. 153
  4. 154
  5. 155
  6. 156
  7. 157
  8. 158
  9. 159
  10. 160

Question 151

Multiple choice Arraylists
ArrayList<Integer> list = new…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 152

Multiple choice Arraylists
ArrayList<String> list = null;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 153

Multiple choice Arraylists
ArrayList<String> list = new ArrayList<String>();…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 154

Multiple choice Arraylists
ArrayList<String> list = new ArrayList<String>();…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 155

Multiple choice Arraylists
public static ArrayList<Integer> buildList(int[] arr) { ArrayList<Integer> result = new ArrayList<Integer>(); for (int val : arr) { if (val % 2 == 0)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 156

Multiple choice Arraylists
public static void removeNegatives(ArrayList<Integer> list) { for (int i = 0;i < list.size();i++) { if (list.get(i) < 0)…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 157

Multiple choice Arraylists
The Player class is defined as follows: public class Player { private String name; private int score; public Player(String name, int score) { this.name = name;…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 158

Multiple choice Arraylists
public static void insertBeforeOld(ArrayList<String> words) { for (int i = 0;i < words.size();i++) { if…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 159

Multiple choice Arraylists
public static int processAndReturn(ArrayList<Integer> nums) { int total = 0; for (int i = 0;i < nums.size();i++) { int val = nums.get(i);…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 160

Multiple choice Arraylists
Consider the following method, intended to remove every String whose length is less than 3 from list.
public static void cleanup(ArrayList<String> list)
{
    for (int i = 0; i < list.size(); i++)
    {
        if (list.get(i).length() < 3)
        {
            list.remove(i);
        }
    }
}
Given the initial list ["a", "bb", "ccc", "dd", "eeee", "ff", "gg"], what does list contain after a call to cleanup(list)?
Pick an answer, then check it. The solution opens in a window.
Question 151 of 173
Page 16 of 18