Consider the following code segment.
ArrayList

ArrayList Quiz

Quiz
•
Computers
•
12th Grade
•
Hard
brent hopkins
Used 3+ times
FREE Resource
16 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
[100, 300, 400]
[200, 300]
[200, 400]
Nothing is printed because the code segment does not compile.
Nothing is printed because an IndexOutOfBoundsException will occur.
2.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method countNegatives, which searches an ArrayList of Integer objects and returns the number of elements in the list that are less than 0.
public static int countNegatives(ArrayList
It has no impact on the behavior of the method.
It causes the method to ignore the last element in arr.
It causes the method to throw an IndexOutOfBoundsException.
It reduces the size of arr by 1 and the last element will be removed.
It changes the number of times the loop executes, but all indexes in arr will still be accessed.
3.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method findValue, which takes an ArrayList of String elements and a String value as parameters and returns true if the String value is found in the list and false otherwise.
public static boolean findValue(ArrayList
It has no impact on the behavior of the method.
It will cause the method to return a different result when the key value is not in the list.
It will cause the method to return a different result when the key value is found only at the first index in the list.
It will cause the method to return a different result when the key value is found only at the last index in the list.
It will cause the method to throw an array index out of bounds exception.
4.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method, inCommon, which takes two Integer ArrayList parameters. The method returns true if the same integer value appears in both lists at least one time, and false otherwise.
public static boolean inCommon(ArrayList
It has no impact on the behavior of the method.
It will cause the method to return a different result when the common value is not in the list.
It will cause the method to return a different result when the common value is found only at the first index in the list.
It will cause the method to return a different result when the common value is found only at the last index in the list.
It will cause the method to throw an array index out of bounds exception.
5.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
What is printed as a result of executing the code segment?
Alex Alex Alex
Alex Alex Alex Alex Bob Carl
Alex Bob Carl Alex Alex Alex
Alex Bob Carl Alex Bob Carl
Nothing is printed because the first print statement will cause a runtime exception to be thrown.
6.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
In the following code segment, assume that the ArrayList wordList has been initialized to contain the String values ["apple", "banana", "coconut", "lemon", "orange", "pear"]. int count = 0; for (String word : wordList) { if (word.indexOf("a") >= 0) { count++; } } System.out.println(count); What is printed as a result of executing the code segment?
1
2
3
4
5
7.
MULTIPLE CHOICE QUESTION
30 sec • 1 pt
Consider the following method, remDups, which is intended to remove duplicate consecutive elements from nums, an ArrayList of integers. For example, if nums contains [1, 2, 2, 3, 4, 3, 5, 6], then after executing remDups(nums), nums should contain [1, 2, 3, 4, 3, 5, 6].
public static void remDups(ArrayList
[1, 1, 2, 3, 3, 4, 5]
[1, 2, 2, 3, 3, 4, 5]
[1, 2, 2, 3, 4, 4, 5]
[1, 2, 2, 3, 4, 5, 5]
[1, 2, 3, 3, 4, 5, 5]
Create a free account and access millions of resources
Similar Resources on Wayground
15 questions
2D Arrays

Quiz
•
9th - 12th Grade
15 questions
Area and Arrays

Quiz
•
10th - 12th Grade
14 questions
Exploring Computer Science

Quiz
•
10th - 12th Grade
20 questions
Java, part I

Quiz
•
11th Grade - University
20 questions
JDVP Activity

Quiz
•
12th Grade - University
15 questions
Data Structures

Quiz
•
12th Grade
12 questions
Unit 7 - ArrayList - Test Review

Quiz
•
9th - 12th Grade
12 questions
Javascript Arrays

Quiz
•
9th - 12th Grade
Popular Resources on Wayground
25 questions
Equations of Circles

Quiz
•
10th - 11th Grade
30 questions
Week 5 Memory Builder 1 (Multiplication and Division Facts)

Quiz
•
9th Grade
33 questions
Unit 3 Summative - Summer School: Immune System

Quiz
•
10th Grade
10 questions
Writing and Identifying Ratios Practice

Quiz
•
5th - 6th Grade
36 questions
Prime and Composite Numbers

Quiz
•
5th Grade
14 questions
Exterior and Interior angles of Polygons

Quiz
•
8th Grade
37 questions
Camp Re-cap Week 1 (no regression)

Quiz
•
9th - 12th Grade
46 questions
Biology Semester 1 Review

Quiz
•
10th Grade