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 141–150 of 173
  1. 141
  2. 142
  3. 143
  4. 144
  5. 145
  6. 146
  7. 147
  8. 148
  9. 149
  10. 150

Question 141

Multiple choice Arraylists
An ArrayList<Integer> named list contains [2, 4, 6, 8, 10]. The following loop runs: for (int i = 0; i…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 142

Multiple choice Arraylists
Consider a method that takes an ArrayList<String> and returns a new ArrayList…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 143

Multiple choice Arraylists
What is the output of the following? ArrayList<Integer> a = new ArrayList<>(); for…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 144

Multiple choice Arraylists
What does list contain after the following loop? ArrayList<Integer> list = new ArrayList<Integer>(); list.add(3); list.add(1);…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 145

Multiple choice Arraylists
What is printed? ArrayList<String> words = new ArrayList<String>(); words.add("cat"); words.add("car"); words.add("dog"); words.add("care"); words.add("card");…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 146

Multiple choice Arraylists

What is printed?

ArrayList<Integer> list = new ArrayList<Integer>();
list.add(4); list.add(4); list.add(3);
list.add(4); list.add(4);
for (int i = 0; i < list.size(); i++) {
    if (list.get(i) == 4) {
        list.remove(i);
    }
}
System.out.println(list);
Pick an answer, then check it. The solution opens in a window.

Question 147

Multiple choice Arraylists

What is printed?

ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 5; i++) { list.add(i * i); }
for (int i = 0; i < list.size() - 1; i++) {
    list.set(i, list.get(i) + list.get(i + 1));
}
System.out.println(list);
Pick an answer, then check it. The solution opens in a window.

Question 148

Multiple choice Arraylists

What is printed?

ArrayList<String> words = new ArrayList<String>();
words.add("cat"); words.add("dog"); words.add("car");
words.add("dot"); words.add("cup");

ArrayList<String> result = new ArrayList<String>();
for (int i = 0; i < words.size(); i++) {
    String w = words.get(i);
    if (w.substring(0, 1).equals("c")) {
        result.add(w);
    }
}
for (int i = result.size() - 1; i >= 0; i--) {
    if (result.get(i).indexOf("a") != -1) {
        result.remove(i);
    }
}
System.out.println(result);
Pick an answer, then check it. The solution opens in a window.

Question 149

Multiple choice Arraylists

What is printed?

ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 1; i <= 6; i++) {
    list.add(i * i);
}
// list = [1, 4, 9, 16, 25, 36]
for (int i = list.size() - 1; i >= 1; i -= 2) {
    list.set(i, list.get(i) - list.get(i - 1));
}
System.out.println(list);
Pick an answer, then check it. The solution opens in a window.

Question 150

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

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 141 of 173
Page 15 of 18