Baidu's library explains that an iterator (iterator) is an object that can be used to traverse some or all of the elements in a standard template repository, each of which represents a definite address in a container.
See Http://baike.baidu.com/link?url=msphHlamyA3yi25fP_4qHomEomPN5Gd9XHo5--5A_ZN0iOj939YrwCirjd8qQIy_ Oimj3pbsnqsuwiezbpdveq
Iterators (Iterator)
An iterator is a design pattern that is an object that can traverse and select objects in a sequence, and the developer does not need to know the underlying structure of the sequence. Iterators are often referred to as "lightweight" objects because they are less expensive to create.
The iterator functionality in Java is relatively simple and can only be moved one way:
(1) Use method iterator () requires the container to return a iterator. The first time you call Iterator's next () method, it returns the first element of a sequence. Note: The iterator () method is an Java.lang.Iterable interface that is inherited by collection.
(2) Use Next () to get the next element in the sequence.
(3) Use Hasnext () to check if there are elements in the sequence.
(4) use remove () to delete the newly returned element of the iterator.
Iterator is the simplest implementation of Java iterators, with more functionality for the listiterator of list design, which can traverse the list in two directions or insert and delete elements from a list.
Iterator Applications:
List L = new ArrayList ();
L.add ("AA");
L.add ("BB");
L.add ("CC");
for (Iterator iter = L.iterator (); Iter.hasnext ();) {
String str = (string) iter.next ();
System.out.println (str);
}
/* Iterator for While loop
Iterator iter = L.iterator ();
while (Iter.hasnext ()) {
String str = (string) iter.next ();
System.out.println (str);
}
*/
What is an iterator (go)