The iterator() method of ArrayList class in Java Collection Framework is used to get an iterator over the elements in this list in proper sequence. The returned iterator is fail-fast.
Parameter: This method do not accept any parameter.
Return Value: This method returns an iterator over the elements in this list in proper sequence
Below examples illustrate the ArrayList.iterator() method:
The list is: [Geeks, for, Geeks, is, a, CS, Students, Portal] The iterator values of list are: Geeks for Geeks is a CS Students Portal
The list is: [10, 15, 30, 20, 5] The iterator values of list are: 10 15 30 20 5
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.