Verified Test Bank Iterators Chapter.16 - Java Foundations 4th Edition | Test Bank with Answer Key by John Lewis by John Lewis, Peter DePasquale, Joe Chase. DOCX document preview.
Chapter 16: Iterators
Multiple Choice Questions:
1) An iterator is
a) an element in a collection.
b) an object that allows access to each element in a collection individually.
c) an interface
d) a loop control variable
e) a five syllable word
2) Which method below is not part of the Iterator interface?
a) add
b) remove
c) next
d) hasNext
e) all of these are methods in the Iterator interface.
3) The only method in the Iterable interface is
a) create
b) iterator
c) destroy
d) remove
e) hasNext
4) When writing a class for an array-based implementation of a list, the class that defines an iterator for the list should be
a) public
b) iterable
c) an interface
d) an inner class
e) none of the above
5) A user defines a class to implement an iterator for a user-defined collection. When an iterator object is created, it needs to know
a) when it was created
b) why it was created
c) the number of elements in the collection
d) the datatype of the elements in the collection
e) none of the above
1) Using the hasNext() and next() methods in a loop is the only way to retrieve all of the list elements using an iterator.
2) A user may not be able to predict the order in which an iterator will return elements from a collection
3) ‘Fail-fast’ means that a program will crash if a collection class supports the Iterable interface but no Iterator object is created.
4) An iterator’s remove method requires the use of a for-each loop.
5) When a user writes code to implement a collection class that implements the Iterable interface, they have to write code for the next and hasNext methods.
6) When a user defines an Iterator class for a user-defined collection, the user must implement the methods in the Iterator interface in a way that detects if the collection is modified independent of the iterator object.
1) roster is an ArrayList of Student objects. Write a segment of code that will modify Roster so that its size becomes 0. Use an iterator.
2) What happens if an Iterator object is active and the underlying collection is updated via collection operations?
3) An ordered list contains elements with values 14, 22, -6, and 35. The list has an Iterator object. In what order will the elements be accessed?
4) What does “fail-safe” mean? How is it used with iterators?
5) What does it mean for a class to be Iterable?
Document Information
Connected Book
Java Foundations 4th Edition | Test Bank with Answer Key by John Lewis
By John Lewis, Peter DePasquale, Joe Chase