0% found this document useful (0 votes)
469 views

Quiz On ArrayLists and Iterators

Quiz

Uploaded by

ratneshkumarg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
469 views

Quiz On ArrayLists and Iterators

Quiz

Uploaded by

ratneshkumarg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 6
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: list.add( "Ann" ); list.add( "Bob" ); list.add( "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 We 87016 Quiz on rapists and Horators ArrayList list = new ArrayList(10) ; list.add( "Andy" ); list.add( "Bart" ); list.add( "Carl" ); list.add( @, "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() ; list.add( “Andy” ); list.add( "Bart" ); list.add( "Carl" ); list.add( "Doug" ); ) list.add( "Elmo" Which of the following will replace the element "Car!" with "Zoltan" ? A, list[2] = "Zoltan" ; B. list.set( "Zoltan", "Carl" ); C. list.add( "Zoltan", list.indexof("Carl") ); D. list.set( list.indexOf("Carl"), "Zoltan" ); 5, Examine the following code: ArrayList list = new ArrayList() 5 list.add( "Andy" 3 list.add( "Bart" ); list.add( "Car" ); list.add( "Doug" ); ) list.add( "Elmo" hipichore.cesuedujavaBiNotes/chapStichapSteuizRev2 ml epan016 (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. list.add( 3, ©B. list.add( 4, C. list.set( 3, D. list.set( 4, 6. Examine the following code: ArrayList list = new ArrayList() ; list.add( “Andy” ); list.add( "Bart" ); list.add( "Carl" ); list.add( "Doug" ); ) list.add( "Elmo" Which of the following will change the list so that it looks like: Andy Bart Doug Elmo A. list.remove( 3 ); © B, list.remove( 2 ); ©. list.add( 2, null ) D, list.set( list.indexOf( "Carl" ), "Doug" ); 7. Examine the following code: ArrayList list = new ArrayList() list.add( "Andy" )5 hipichore.cesuedujavaBiNotes/chapStichapSteuizRev2 ml epan016 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: list.remove( list.size() ); list.remove( list.size()-1 ); list.remove( 5 ); list.clear( "Elmo" ) 8, Examine the following code: ArrayList list = new ArrayList() ; add( “Andy” )5 add( "Bart" ); list.add( "Carl" ); list.add( "Doug" ); list.add( "Elmo" ); Iterator iter = list. 3 while( iter. ) System.out.printIn( 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() ; list.add( "Andy" ); list.add( "Bart" ); list.add( "Carl" ); list.add( "Doug" ); list.add( "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 hipichore.cesuedujavaBiNotes/chapStichapSteuizRev2 ml saa016 (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. hipesichore.cosuedjavaliNotes/chapStichapStauizRev2ml

You might also like