Powered by Blogger.

What is the difference between Iterator and Listiterator ?

>> Saturday, August 20, 2011


There are two Differences are there :

1. We can use Iterator to traverse Set and List and also Map type of Objects. But List Iterator can be used to traverse for List type Objects, but not for Set type of Objects.

That is, we can get a Iterrator object by using Set and List, see here :

 By using Iterator we can retrieve the elements from Collection Object in forward direction only.

Methods in Iterator :

1. hashNext()
2. next()
3. remove()



Iterator ite = Set.iterator();
Iterator ite = List.iterator();


2. But we get List Iterator object only from List interface, see here :

where as List Iterator, which allows you to traverse in either directions. That is List Iterators traverse two directions. So it has another methods hasPrevious() & previous() other than Iterator.

Methods in ListIterator

1. hashNext()
2. next()
3. previous()
4.hashPrevious()
5. remove()
6. nextIndex()
7. previousIndex()


ListIterator listite = List.listIterator();

i.e., we can't get List Iterator object from Set interface. 

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2022. All rights reserved.