Javatpoint Logo
Javatpoint Logo

Java Iterator interface

An iterator is an interface that is used in place of Enumerations in the Java Collection Framework. Moreover, an iterator differs from the enumerations in two ways:

  1. Iterator permits the caller to remove the given elements from the specified collection during the iteration of the elements.
  2. Method names have been enhanced.

Iterator interface is a member connected with Java Collections Framework.


Methods Description
forEachRemaining(Consumer<? super E>action) Performs the given action on each of the element until and unless all the elements have been processed or unless an exception is thrown by the action.
hasNext() Returns a true value if the more number of elements are encountered during iteration.
next() Returns the next specified element during the iteration.
remove() Removes the last element from the collection as provided by the iterator.

Example 1

Test it Now


The list is given as : [Welcome, to, our, website]
After the remove() method is called : [Welcome, to, our]
Next TopicJava Iterator

Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA