Question
1. Which of the following correctly declares an ArrayList? (3 points) I. ArrayList aList = new ArrayList (); II. ArrayList aList = new ArrayList (10);
1.
Which of the following correctly declares an ArrayList? (3 points)
I. ArrayList
II. ArrayList
III. ArrayList
I only | |
II only | |
III only | |
I and II only | |
II and III only |
2.
Which of the following correctly declares an ArrayList? (3 points)
I. ArrayList
II. ArrayList
III. ArrayList
I only | |
II only | |
III only | |
I and II only | |
I and III only |
3.
Assume aList is a valid ArrayList containing the following string values: apple, orange, grape, kiwi, watermelon, peach, banana When the following statement executes, what does aList contain? (3 points) aList.set(3, "lemon");
apple, orange, grape, kiwi, lemon, peach, banana | |
apple, orange, grape, lemon, watermelon, peach, banana | |
apple, orange, grape, kiwi, lemon, watermelon, peach, banana | |
apple, orange, lemon, grape, kiwi, watermelon, peach, banana | |
apple, orange, grape, kiwi, watermelon, peach, banana, lemon, lemon, lemon |
4.
Assume aList is a valid ArrayList containing the following string values: apple, orange, grape, kiwi, watermelon, peach, banana When the following statement executes, what does aList contain? (3 points) aList.set(1, "raspberry");
apple, orange, grape, kiwi, watermelon, peach, banana | |
apple, raspberry, grape, kiwi, watermelon, peach, banana | |
apple, raspberry, orange, grape, watermelon, peach, banana | |
raspberry, orange, grape, kiwi, watermelon, peach, banana | |
raspberry, apple, orange, grape, kiwi, watermelon, peach, banana |
5.
Assume aList is a valid ArrayList containing the following values: 3, 95, 86, 11, 18, 42, 73 Which of the following places 55 immediately before 42 in aList? (3 points)
aList.add(55); | |
aList.add(5, 55); | |
aList.add(6, 55); | |
aList.add(42, 55); | |
aList.add(55, 6); |
6.
Assume aList is a valid ArrayList containing the following: purple, red, blue, yellow, green, pink, black, gold Which of the following removes blue from aList? (3 points)
I. aList.remove(2, "blue");
II. aList.remove("blue");
III. aList.remove("blue", 2);
I only | |
II only | |
III only | |
I and II only | |
II and III only |
7.
Assume aList is a valid ArrayList containing the following: purple, red, blue, yellow, green, pink, black, gold Which of the following removes yellow from aList? (3 points)
I. aList.remove(3);
II. aList.remove("yellow");
III. aList.remove(3, "yellow");
I only | |
I and II only | |
I and III only | |
II and III only | |
I, II, and III |
8.
What is the size of the ArrayList aList after the following code segment is executed? (3 points) ArrayList
3 | |
5 | |
6 | |
7 | |
An IndexOutOfBoundsException error occurs |
9.
What is the size of the ArrayList aList after the following code segment is executed? (3 points)
ArrayList
0 | |
1 | |
2 | |
4 | |
An IndexOutOfBoundsException error occurs |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started