AbstractList iterator() method in Java with Examples
The iterator() method of java.util.AbstractList class is used to return an iterator over the elements in this list in proper sequence.
This implementation returns a straightforward implementation of the iterator interface, relying on the backing list’s size(), get(int), and remove(int) methods.
public Iterator iterator()
Returns Value: This method returns an iterator over the elements in this list in proper sequence.
Below are the examples to illustrate the iterator() method.
ArrayList : [10, 20, 30, 40, 50] Value is : 10 Value is : 20 Value is : 30 Value is : 40 Value is : 50
ArrayList : [A, B, C, D, E] Value is : A Value is : B Value is : C Value is : D Value is : E
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.