What is the difference between Iterator and Listiterator ?
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 :
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 :
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 :
Methods in ListIterator
1. hashNext()
2. next()
3. previous()
4.hashPrevious()
5. remove()
6. nextIndex()
7. previousIndex()
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.