CS 151 Lecture 12: Sections 5.5-5.6

104 views2 pages

Document Summary

An iterator is an object that has methods that allow you to process a collection of items one at a time lets you step through each item and interact with it as needed. Repetitive process, closely related to the idea of loops. Every iterator object has a method called hasnext that returns a boolean value indicating if there is at least one more item to process. Therefore the hasnext method can be used as a condition of a loop to control the processing of each item. An iterator also has a method called next to retrieve the next item in the collection to process. Scanner and hasnext used to define iterators. The scanner class also has specific variations of the hasnext method, such as the hasnextint and hasnextdouble methods, which allow you to determine if the next input token is a particular type. The delimiters used to separate tokens in a scanner object can be explicitly set as needed.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions