
ArrayLists

Quiz
•
Computers
•
11th - 12th Grade
•
Medium
Used 16+ times
FREE Resource
10 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What is printed as a result of executing the following code?
ArrayList<Integer> alist = new ArrayList<Integer>();
alist.add(1);
alist.add(2);
alist.remove(1);
alist.add(1, 3);
alist.set(1, 4);
alist.add(5);
System.out.println(alist);
[1, 4, 5]
[1, 4, 3, 5]
[2, 4, 5]
[2, 4, 3, 5]
2.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Which statement below is the correct way to retrieve the first element in the nums ArrayList?
nums.get(0)
nums[0]
nums(0)
nums[1]
3.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Given the ArrayList nums with the values [3, 7, 6, 0], what code below is the proper way to change the 7 to be a 5?
nums.set(1, 5)
nums.set(7, 5)
nums.set(5, 2)
nums[2] = 5
4.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What is printed as a result of executing the following code segment?
List<Integer> list1 = new ArrayList<Integer>();
list1.add(new Integer(1));
list1.add(new Integer(2));
list1.add(new Integer(3));
list1.set(2, new Integer(4));
list1.add(2, new Integer(5));
list1.add(new Integer(6));
System.out.println(list1);
[1, 2, 3, 4, 5]
[1, 2, 4, 5, 6]
[1, 2, 5, 4 ,6]
[1, 5,2, 4 ,6]
5.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Given the following code and assume that nums initially contains [0, 0, 4, 2, 5, 0, 3], what will nums contain as a result of executing numQuest?
private List<Integer> nums;
// precondition: nums.size() > 0;
// nums contains Integer objects
public void numQuest()
{
int k = 0;
Integer zero = new Integer(0);
while (k < nums.size())
{
if (nums.get(k).equals(zero))
nums.remove(k);
else
k++;
}
}
[0, 4, 2, 5, 3]
[3, 5, 2, 4, 0, 0, 0]
[0, 0, 0, 4, 2, 5, 3]
[4, 2, 5, 3]
6.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
Which of the following best describes the behavior of process1 and process2 (shown below)?
public static List<Integer> process1(int n)
{
List<Integer> someList = new ArrayList<Integer>();
for (int k = 0; k < n; k++)
someList.add(k);
return someList;
}
public static List<Integer> process2(int n)
{
List<Integer> someList = new ArrayList<Integer>();
for (int k = 0; k < n; k++)
someList.add(k, k);
return someList;
}
Both methods produce the same result, and process1 is faster than process2.
The two methods produce different results and take the same amount of time.
The two methods produce different results, and process1 is faster than process2.
The two methods produce different results, and process2 is faster than process1.
Both methods produce the same result and take the same amount of time.
7.
MULTIPLE CHOICE QUESTION
2 mins • 1 pt
What is printed as a result of executing the following code segment?
List<Integer> aList = new ArrayList<Integer>();
aList.add(new Integer(1));
aList.add(new Integer(2));
aList.add(1, new Integer(5));
aList.set(1, new Integer(4));
aList.add(new Integer(6));
aList.add(new Integer(3));
System.out.println(aList);
[1, 2, 5, 4, 6, 3]
[6, 5, 4, 3, 2, 1]
[1, 2, 3, 4, 5, 6]
[1, 4, 2, 6, 3]
. [1, 2, 4, 6, 3]
Create a free account and access millions of resources
Similar Resources on Wayground
10 questions
12 CS 6-10 One Mark

Quiz
•
12th Grade
15 questions
Records and Files

Quiz
•
8th - 11th Grade
10 questions
Python lists and tuples

Quiz
•
12th Grade
10 questions
Python Quiz for Grade 11 List, Tuple & Strings

Quiz
•
11th Grade
15 questions
Computer Science - Python

Quiz
•
9th - 12th Grade
15 questions
Python Revision Tour - I

Quiz
•
12th Grade
14 questions
9.1.2 - Starter Quiz

Quiz
•
7th - 11th Grade
10 questions
Data Handling in Python

Quiz
•
11th Grade
Popular Resources on Wayground
10 questions
Lab Safety Procedures and Guidelines

Interactive video
•
6th - 10th Grade
10 questions
Nouns, nouns, nouns

Quiz
•
3rd Grade
10 questions
9/11 Experience and Reflections

Interactive video
•
10th - 12th Grade
25 questions
Multiplication Facts

Quiz
•
5th Grade
11 questions
All about me

Quiz
•
Professional Development
22 questions
Adding Integers

Quiz
•
6th Grade
15 questions
Subtracting Integers

Quiz
•
7th Grade
9 questions
Tips & Tricks

Lesson
•
6th - 8th Grade
Discover more resources for Computers
20 questions
Digital Citizenship

Quiz
•
8th - 12th Grade
35 questions
Computer Baseline Examination 2025-26

Quiz
•
9th - 12th Grade
13 questions
Problem Solving Process

Quiz
•
9th - 12th Grade
10 questions
Understanding Algorithms with Pseudocode and Flowcharts

Interactive video
•
9th - 12th Grade
19 questions
AP CSP Unit 1 Review (code.org)

Quiz
•
10th - 12th Grade