Java/Iterator: Difference between revisions
From charlesreid1
(Redirected page to Java/Iterable#Iterable vs Iterator) |
No edit summary |
||
| Line 1: | Line 1: | ||
Also see [[Java/Iterable#Iterable vs Iterator]] | |||
Iterator is a wrapper class - think of it as a lightweight scanner object for an iterable data container. | |||
The Linked List class ([https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html javadocs link]) utilizes a ListIterator class ([http://docs.oracle.com/javase/7/docs/api/java/util/ListIterator.html javadocs link]). The ListIterator class is basically similar to the Iterator class but adds a few additional methods - add, hasPrevious, previous, hasNext, next, etc. | |||
To get a ListIterator to a list, use listIterator() method. | |||
To get a ListIterator to a list pointing to index i, use the listIterator(int i) method. | |||
Revision as of 07:00, 19 June 2017
Also see Java/Iterable#Iterable vs Iterator
Iterator is a wrapper class - think of it as a lightweight scanner object for an iterable data container.
The Linked List class (javadocs link) utilizes a ListIterator class (javadocs link). The ListIterator class is basically similar to the Iterator class but adds a few additional methods - add, hasPrevious, previous, hasNext, next, etc.
To get a ListIterator to a list, use listIterator() method.
To get a ListIterator to a list pointing to index i, use the listIterator(int i) method.