Java learning notes -- iterator and java learning notes --
To achieve uniform traversal of different types of containers, an iterator is used. It mainly uses two interfaces: Iterator and Iterable. The class that implements the Iterable interface indicates that this class can be traversed using the iterator, such as List and Set.Target class to be traversed. The class that implements the Iterator interface indicates that this class is a specific class (such as List, Set)Iterator classTo traverse the target class. The class that implements the Iterable <T> interface must implement the following methods. Methods that implement this interface can be traversed using Foreach.
Iterator <T> iterator ();
This method returns a class that implements the Iterator interface for traversal.
The class implementing the Iterator <E> interface must implement the following three methods to traverse the specific class. This class can be used to return values of the previous method.
Boolean hasNext (); E next (); void remove ();