0 ratings 0% found this document useful (0 votes) 525 views 6 pages Quiz On ArrayLists and Iterators
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Save Quiz on ArrayLists and Iterators For Later ran016
(Quiz on Arayists and Herat
created: Jan. 06, 2000; revised: 10/05/03, 06/05/06, 07/05/07, 11/02/2012
appear in the box after each question
on ArrayLists and Iterators
Instructions: For each question, choose the single best answer. Make your choice by clicking on its
button. You can change your answers at any time. When the quiz is graded, the correct answers will
C. ArrayList[Object] list
®D. ArrayList list
D
1. Declare and construct an ArrayList with an initial capacity of 20 references to Object.
A. Object list(20) = new ArrayList() 5
OB, ArrayList list[20] = new ArrayList() 5
new ArrayList(20) ;
new ArrayList(20) ;
2. Examine the following code:
[Link]( "Ann" );
[Link]( "Bob" );
[Link]( "Eve" );
A. 3,3
B. 3,10
Cc. 10,3
D. 10,10
ArrayList list = new ArrayList(1@) 5
After the code has executed, what is the capacity of List? What is its size?
3. Examine the following code:
hhipesichore cosuedujavaliNotes/chapStichapStcuieRev2ml
We87016 Quiz on rapists and Horators
ArrayList list = new ArrayList(10) ;
[Link]( "Andy" );
[Link]( "Bart" );
[Link]( "Carl" );
[Link]( @, "Ev
What element will be at index 2 of the list?
A. Eve
B. Andy
© c. Bart
D. carl
4. Examine the following code:
ArrayList list = new ArrayList() ;
[Link]( “Andy” );
[Link]( "Bart" );
[Link]( "Carl" );
[Link]( "Doug" );
)
[Link]( "Elmo"
Which of the following will replace the element "Car!" with "Zoltan" ?
A, list[2] = "Zoltan" ;
B. [Link]( "Zoltan", "Carl" );
C. [Link]( "Zoltan", [Link]("Carl") );
D.
[Link]( [Link]("Carl"), "Zoltan" );
5, Examine the following code:
ArrayList list = new ArrayList() 5
[Link]( "Andy"
3
[Link]( "Bart" );
[Link]( "Car" );
[Link]( "Doug" );
)
[Link]( "Elmo"
[Link]/chapStichapSteuizRev2 mlepan016 (Qu2 on ArayLists and erates
Which of the following will change the list so that it looks like:
Andy
Bart
Carl
Doug
Oscar
Elmo
A. [Link]( 3,
©B. [Link]( 4,
C. [Link]( 3,
D. [Link]( 4,
6. Examine the following code:
ArrayList list = new ArrayList() ;
[Link]( “Andy” );
[Link]( "Bart" );
[Link]( "Carl" );
[Link]( "Doug" );
)
[Link]( "Elmo"
Which of the following will change the list so that it looks like:
Andy
Bart
Doug
Elmo
A. [Link]( 3 );
© B, [Link]( 2 );
©. [Link]( 2, null )
D, [Link]( [Link]( "Carl" ), "Doug" );
7. Examine the following code:
ArrayList list = new ArrayList()
[Link]( "Andy" )5
[Link]/chapStichapSteuizRev2 mlepan016
list.
list.
list.
list.
Andy
Bart
carl
Doug
A.
©B.
c.
D.
list.
list.
A
B.
c.
hipschorte cesu
(Qu2 on ArayLists and erates
add( "Bart" );
add( "Carl" );
add( "Doug" );
add( "Elmo" );
Which of the following will change the list so that it looks like:
[Link]( [Link]() );
[Link]( [Link]()-1 );
[Link]( 5 );
[Link]( "Elmo" )
8, Examine the following code:
ArrayList list = new ArrayList() ;
add( “Andy” )5
add( "Bart" );
[Link]( "Carl" );
[Link]( "Doug" );
[Link]( "Elmo" );
Iterator iter = list. 3
while( iter. )
[Link]( iter. 3
Fill in the blanks so that the list is printed,
iterator() hasNext() next()
iterator() next() nextElement()
elements() empty() next()
iterator() more() get()
9. Examine the following code:
5 edujavabiNotesichapStichapSteuizRov2 im!87016 Quiz on rapists and Horators
ArrayList list = new ArrayList() ;
[Link]( "Andy" );
[Link]( "Bart" );
[Link]( "Carl" );
[Link]( "Doug" );
[Link]( "Elmo" );
while( name : )
System. out. print1n( )5
Fill in the blanks so that the list is printed,
© A. String list name
B. String iterator() — next()
c. int string name
D. iterator() String list
A
10. which of the following declarations would be appropriate for a list that is expected to contain
integers?
A. ArrayList list = new ArrayList() ;
B. ArrayList list = new ArrayList() ;
® C, ArrayList list = new ArrayList() ;
D. ArrayList list = new ArrayList() ;
11. What is the interface implemented by a class (such as ArrayList) that implements the
iterator() method?
A. Iterator
® B. Iterable
B
12. What is the interface implemented by an iterator object itself?
© A. Iterator
B. Iterable
[Link]/chapStichapSteuizRev2 mlsaa016 (Quz on ArayLists and erator
13, What is true of classes that can be used with the enhanced for loop?
A. Allclasses can use the enhanced for loop.
B. Only ArrayList can use the enhanced for loop.
C. Only ArrayList and arrays can use the enhanced for loop.
© D, Any class that implements Iterable can use the enhanced for loop.
D
14. What equals() method must you override when defining a class of objects you expect to hold in
aArrayList ?
® A. public boolean equals( Object )
B. public boolean equals( ArrayList )
©. boolean equals( Object )
D. private int equals( Object )
[rede uz
The number you got right: [14 Percent Correct: 100 Letter Grade:
if you have returned here from another page, or have re-loaded this page, you will
need to click again on each of your choices for the grading program to work correctly.
‘You may want to press the SHIFT KEY while clicking to clear the old answers.
[Link]/chapStichapStauizRev2ml