Iterator

 Cursors of Collection Framework

  • cursors are mainly used to access the elements of any collection.
  • we have the following 3 types of cursors in the Collection Framework.

  1. Iterator
  2. ListIterator
  3. Enumeration

Iterator:

  • this cursor is used to access the elements in a forward direction
  • this cursor can be applied to Any Collection.
  • while accessing the methods we can also delete the elements.
  • Iterator is the interface and we can not create an object directly.
  • If we want to create an object for Iterator we have to use the iterator() method
Creation of Iterator.

 Iterator it =c.iterator();

here iterator() method internally creates and returns an object of a class that implements the Iterator interface.

Iterator Methods:
  1. boolean hasNext()
  2. Object next()
  3. void remove()
Example:



Post a Comment

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