CS 2114 Chapter Notes - Chapter Iterators and List Iterators: Inner Class
Document Summary
Iterators are a program component that allows one to traverse a collection of data (i. e. a list). Iteration refers to one complete traversal where each data item is considered once. Collections can be modified, added, or removed while traversing: example: int listsize = namelist. getlength(); for(int position = 1 ; position <= listsize; position++) For an array-based implementation of a list, getentry can retrieve the. If a chain of linked nodes represents the list"s entries, getentry must move from node to node until it locates the desired node. The package java. util contains the iterator and listiterator interfaces. Contains the methods hasnext, next, and remove. The position of the iterator is positioned either right before the first. If next is called from the last entry, a nosuchelementexception is returned. entry in a collection, between two entries, or after the last entry. Next entry refers to the entry right after the iterator"s cursor: example: displaying all of the entries in a list.