Рет қаралды 21
Java Iterator Cursor II Collection Framework II Java Tutorial for beginner with coding
1. Iterator
Iterators in Java are used in the Collection framework to retrieve elements one by one. It is a universal iterator as we can apply it to any Collection object. By using Iterator, we can perform both read and remove operations. It is an improved version of Enumeration with the additional functionality of removing an element.
Methods of Iterator Interface in Java
The iterator interface defines three methods as listed below:
1. hasNext(): Returns true if the iteration has more elements.
public boolean hasNext();
2. next(): Returns the next element in the iteration. It throws NoSuchElementException if no more element is present.
public Object next();
3. remove(): Removes the next element in the iteration. This method can be called only once per call to next().
public void remove();
#iterator #collectionframework #javacursor