Log in
Sign up for FREE
arrow_back
Library

Arraylists Quiz

star
star
star
star
star
Last updated almost 2 years ago
22 questions
1
1
1
1
1
Question 5
5.

Quiz: Which of the following would fill blank <*1> to add a new It to itListOne?

1
1
1
1
1
1
Question 11
11.
1
Question 12
12.
1
1
1
1
1
1
Question 18
18.
1
Question 19
19.
1
Question 20
20.
1
Question 21
21.
1
Question 22
22.
Question 1
1.

What is output by the code below? ArrayList<String> list = new ArrayList<String>(); list.add("three"); list.remove(0); list.add("one"); System.out.println(list);

Question 2
2.

What is output by the code below? ArrayList<String> list = new ArrayList<String>(); list.add("one"); list.set(0, "two"); list.add(0, "three"); System.out.println(list);

Question 3
3.

What is output by the code below? List<String> list = new ArrayList<String>(); list.add("one"); list.add(0,"two"); list.set(0,"three"); list.add(1,"four"); list.remove(0); list.set(1,"five"); System.out.println(list);

Question 4
4.

What is output by the code below? List<String> bigList = new ArrayList<String>(); bigList.add(0,"one"); bigList.add("two"); bigList.add(0,"three"); bigList.add("four"); bigList.remove(0); bigList.add(0,"five"); bigList.set(2,"six"); bigList.set(3,"seven"); bigList.add("zero"); System.out.println(bigList.indexOf("six"));

Question 6
6.

What is the output by the code below? java public class It { private int stuff; private String word; public It(int x, String w){ stuff = x; word = w; } public int getStuff(){ return stuff; } public String toString(){ return "" + stuff + " " + word ; } } //code in client class ArrayList<It> x; x = new ArrayList<It>(); x.add(new It(5, "dog")); x.add(new It(3, "cat")); System.out.println(x.get(0).getStuff());

Question 7
7.

Consider the following Dog class. Which of the following answer choices would create a List of Dog references?

Question 8
8.

Given the Dog and DogPound classes, which code could fill line 1 so that method printDogs would print all Dogs in the DogPound?

Question 9
9.

// client code found in PigRunner.java
ArrayList< Pig > list;
list = new ArrayList< Pig >();
< *1 >
Which of the following could fill < *1 > to add a Pig to the list?
I. list.add( 5 );
II. list.add( 5, "piggy" );
III. list.add( new Pig( 5, "piggy" ) ) ;

Question 10
10.

Consider the following Pig class and client code below. class Pig { public Pig( int x, String y ) { //code not shown } } // client code found in PigRunner.java ArrayList< Pig > list; list = new ArrayList< Pig >(); // several Pigs have been added to the list < *1 > Which of the following could fill < *1 > to print out each Pig in the list on a separate line? I. for( Pig it : list ) System.out.println( it ); II. for( Pig it : list ) System.out.println( list.get( it ) ); III. for( Pig it : list ) System.out.println( it );

Question 13
13.
Question 14
14.
Question 15
15.
Question 16
16.
Question 17
17.