Iterators Chapter.16 Test Questions & Answers - Instructor Test Bank | Java Foundations 5e Lewis by John Lewis. DOCX document preview.

Iterators Chapter.16 Test Questions & Answers

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

True/False Questions:

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.

Short Answer Questions:

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.

Iterator<Student> it = roster.iterator();

while (it.hasNext() )

{

it.next();

it.remove();

}

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

Document Type:
DOCX
Chapter Number:
16
Created Date:
Aug 21, 2025
Chapter Name:
Chapter 16 Iterators
Author:
John Lewis

Connected Book

Instructor Test Bank | Java Foundations 5e Lewis

By John Lewis

Test Bank General
View Product →

$24.99

100% satisfaction guarantee

Buy Full Test Bank

Benefits

Immediately available after payment
Answers are available after payment
ZIP file includes all related files
Files are in Word format (DOCX)
Check the description to see the contents of each ZIP file
We do not share your information with any third party