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 161–170 of 173
  1. 161
  2. 162
  3. 163
  4. 164
  5. 165
  6. 166
  7. 167
  8. 168
  9. 169
  10. 170

Question 161

Multiple choice Arraylists
Consider the following code segment.
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i = 1; i <= 6; i++)
{
    a.add(i * 3);
}
for (int i = 0; i < a.size(); i++)
{
    if (i % 2 == 0)
    {
        a.set(i, a.get(i) + i);
    }
}
System.out.println(a);
What is printed?
Pick an answer, then check it. The solution opens in a window.

Question 162

Multiple choice Arraylists
Consider the following code segment.
ArrayList<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(2);
list.add(3);
list.add(2);

for (int i = 0; i < list.size(); i++)
{
    if (list.get(i) == 2)
    {
        list.remove(i);
    }
}
System.out.println(list);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 163

Multiple choice Arraylists
Which of the following operations is valid for a primitive array declared as int[] a but not for an ArrayList<Integer> list?
Pick an answer, then check it. The solution opens in a window.

Question 164

Multiple choice Arraylists
Consider the following code segment.
ArrayList<String> list = new ArrayList<String>();
list.add("A");
list.add("B");
list.add("C");
list.add(1, "X");
list.add(3, "Y");
list.remove(0);
System.out.println(list);
What is printed when the code segment executes?
Pick an answer, then check it. The solution opens in a window.

Question 165

Multiple choice Arraylists
Consider the following code segment. ArrayList<String> a = new ArrayList<String>(); a.add("x"); a.add("y"); ArrayList<String>…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 166

Multiple choice Arraylists
Consider the following code segment. ArrayList<Integer> list = new ArrayList<Integer>(); list.add(10); list.add(20); list.add(30);…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 167

Multiple choice Arraylists
A method is intended to insert target into an ArrayList<Integer> called nums immediately after the first element that is strictly greater than target. If no…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 168

Multiple choice Arraylists
Consider the following class. public class Reading { private String sensor; private double value; public Reading(String s, double v) { sensor = s; value = v; }…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 169

Multiple choice Arraylists
Consider the following code segment. ArrayList<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(2);…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 170

Multiple choice Arraylists
Consider the following code segment. ArrayList<String> list = new ArrayList<String>(); list.add("A");…

Sign up now. It's free!

See the full question with its answer and worked solution.

Question 161 of 173
Page 17 of 18