- We can apply Iterator concept for any Collection object, hence it is universal cursor.
- By using Iterator we can perform both read and remove operations.
- We can create Iterator object by using iterator() method of Collection interface.
public Iterator iterator();
//where c is any Collection object
Iterator interface defines the following three methods:
public Object next()
public void remove()
let's see a simple example for better understanding:
public static void main(String args)
ArrayList al=new ArrayList();
- By using Enumeration and Iterator, we can move only forward direction and we can?t move to the backward direction, hence these are the single direction cursors.
- By using Iterator we can perform only read and remove operations and we can?t perform replacement of new objects.
- So to overcome these limitations of Iterator, we should go to ListIterator.
Java Training | Python Training | Machine Learning with Python Training | Deep Learning with Python Training | Data Science with Python Training | Projects
Silansoftware Pvt.Ltd, BBSR Call to: 0674-2361252