Technical Discussion :: Java
Home > Freshers > Technical Interview Questions > Java
66. What is an Iterator ? How do you traverse through a collection using its Iterator?
Answer:
Iterator allows to traverse the collection and also it has methods which enables to obatin or remove elements. ListIterator adds the feature of traversing the list bi-directionally, also modify the elememts.
Eg.: Iterator itr = al.iterator();
while(itr.hasNext()) {}
Asked In :: iGate Syntel Inc. Accenture
Iterator allows to traverse the collection and also it has methods which enables to obatin or remove elements. ListIterator adds the feature of traversing the list bi-directionally, also modify the elememts.
Eg.: Iterator itr = al.iterator();
while(itr.hasNext()) {}
Iterator allows us to traverse the elements in the collection.