
ArrayLists
Quiz
•
Computers
•
11th - 12th Grade
•
Practice Problem
•
Medium
Used 16+ times
FREE Resource
Enhance your content in a minute
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]
Access all questions and much more by creating a free account
Create resources
Host any resource
Get auto-graded reports

Continue with Google

Continue with Email

Continue with Classlink

Continue with Clever
or continue with

Microsoft
%20(1).png)
Apple
Others
Already have an account?
Similar Resources on Wayground
15 questions
Mengenal Internet dan Jaringan Local
Quiz
•
12th Grade
10 questions
Bài 25 tin 10
Quiz
•
9th Grade - University
15 questions
Lua Review Corona SDK with Notepad++
Quiz
•
10th - 12th Grade
14 questions
ISTQB FOUNDATION 4.0 | Tutorial 41
Quiz
•
12th Grade
10 questions
ASSO - Linux, podstawowe zagadnienia dotyczące systemu i sieci
Quiz
•
9th - 12th Grade
10 questions
Soal BAB V PemWeb
Quiz
•
12th Grade
10 questions
EXCEL 365
Quiz
•
9th - 12th Grade
10 questions
Khởi động
Quiz
•
9th - 12th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
22 questions
fractions
Quiz
•
3rd Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
20 questions
Context Clues
Quiz
•
6th Grade
15 questions
Equivalent Fractions
Quiz
•
4th Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
