Advanced Java Tutorial

Total available pages count: 55
Subject - Java Technologies

Collection interface

Iterator interface

The interface provides the facility of an iterating element in forwarding direction. There is various ways to traverse the collection element,

  • By Iterator interface
  • By for-each loop
  • By for loop
  • By ListIterator Interface
  • By forEach() method
  • By forEachRemaining() method

3 method in the iterable interface,

  1. public boolean hasNext() - Returns true if the iterator has more element or it returns false
  2. public Object next() - Returns the element & move the cursor pointer to the next element
  3. public void remove() - Remove the last element returned by the iterator

Iterable Interface

The interface has a root interface for all collection classes. the collection interface extends the interface & all the subclasses of the collection interface can implement the iterable has one abstract method & it returns an iterator over an element of type T.

Itreator<T> iterator()