ListIterator

 ListIterator:

  • this cursor is used to access the elements of the Collection in both forward and backward directions.
  • this cursor can be applied only for List category Collections.
  • while accessing the methods we can also add, set and delete elements.
  • ListIterator is the interface and we can not create objects directly.

  • if we want to create an object for Listiterator, we must use the listIterator() method.
Creation of ListIterater:

ListIterator<E> it = l.listiterator();

here, the listIterator() method internally creates and returns an object of a class that implements the Listiterator interface.


Methods:

  • boolean hasNext();
  • Object next();
  • boolean hasPrevious();
  • Object previous(); 
  • int nextIndex();
  • int previousIndex();
  • void remove();
  • void set(Object obj);
  • void add(Object obj);

Example:






Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.