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 aList = new ArrayList ();

II. ArrayList aList = new ArrayList (10);

III. ArrayList = new ArrayList(10);

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 aList = new ArrayList ();

II. ArrayList = new ArrayList(10);

III. ArrayList aList = new ArrayList(10);

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 aList = new ArrayList (3); aList.add(3.5); aList.add(4.3); aList.set(1, 12.3); aList.add(1, 18.9); aList.remove(2); aList.set(0, 20.3); aList.add(24.8);

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 aList = new ArrayList (3); aList.add(3.5); aList.add(4.3); aList.add(1, 12.3); aList.set(2, 18.9); aList.remove(1); aList.set(0, 20.3); aList.remove(1); aList.add(24.8);

0

1

2

4

An IndexOutOfBoundsException error occurs

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!