Arraylists Quiz
By Mickey Arnold
starstarstarstarstarstarstarstarstarstar
Last updated 10 months ago
22 Questions
1 point
1
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);
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);
1 point
1
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);
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);
1 point
1
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);
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);
1 point
1
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"));
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"));
1 point
1
Question 5
5.
Quiz: Which of the following would fill blank <*1> to add a new It to itListOne?
Quiz: Which of the following would fill blank <*1> to add a new It to itListOne?
1 point
1
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());
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());
1 point
1
Question 7
7.
Consider the following Dog class. Which of the following answer choices would create a List of Dog references?
Consider the following Dog class. Which of the following answer choices would create a List of Dog references?
1 point
1
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?
Given the Dog and DogPound classes, which code could fill line 1 so that method printDogs would print all Dogs in the DogPound?
1 point
1
Question 9
9.
// client code found in PigRunner.javaArrayList< 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" ) ) ;
// 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" ) ) ;
1 point
1
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 );
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 );
1 point
1
Question 11
11.
1 point
1
Question 12
12.
1 point
1
Question 13
13.
1 point
1
Question 14
14.
1 point
1
Question 15
15.
1 point
1
Question 16
16.
1 point
1
Question 17
17.
1 point
1
Question 18
18.
1 point
1
Question 19
19.
1 point
1
Question 20
20.
1 point
1
Question 21
21.
1 point
1
Question 22
22.