它是一个接口
public interface Iterator<E>
它可遍历集合对象
An iterator over a sequence of objects, such as a collection.
扔出异常
If a collection has been changed since the iterator was created, methods next and hasNext() may throw a ConcurrentModificationException.
It is not possible to guarantee that this mechanism works in all cases of unsynchronized concurrent modification.
It should only be used for debugging purposes. Iterators with this behavior are called fail-fast iterators.
实现这个接口,去遍历
Implementing Iterable and returning an Iterator allows your class to be used as a collection with the enhanced for loop.
方法
/**
* Returns true if there is at least one more element, false otherwise.
* @see #next
*/
public boolean hasNext();
/**
* Returns the next object and advances the iterator.
*
* @return the next object.
* @throws NoSuchElementException
* if there are no more elements.
* @see #hasNext
*/
public E next();
/**
* Removes the last object returned by {@code next} from the collection.
* This method can only be called once between each call to {@code next}.
*
* @throws UnsupportedOperationException
* if removing is not supported by the collection being
* iterated.
* @throws IllegalStateException
* if {@code next} has not been called, or {@code remove} has
* already been called after the last call to {@code next}.
*/
public void remove();