ArrayList iterator() method in Java with Examples Last Updated : 11 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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. Syntax: Iterator iterator() 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: Program 1: JAVA // Java code to illustrate iterator() import java.util.*; public class GFG { public static void main(String[] args) { // Create and populate the list ArrayList<String> list = new ArrayList<>(); list.add("Geeks"); list.add("for"); list.add("Geeks"); list.add("is"); list.add("a"); list.add("CS"); list.add("Students"); list.add("Portal"); // Displaying the list System.out.println("The list is: \n" + list); // Create an iterator for the list // using iterator() method Iterator<String> iter = list.iterator(); // Displaying the values after iterating // through the list System.out.println("\nThe iterator values" + " of list are: "); while (iter.hasNext()) { System.out.print(iter.next() + " "); } } } Output: 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 Program 2: Java // Java code to illustrate iterator() import java.util.*; public class GFG { public static void main(String args[]) { // Creating an empty ArrayList ArrayList<Integer> list = new ArrayList<Integer>(); // Use add() method to add // elements into the list list.add(10); list.add(15); list.add(30); list.add(20); list.add(5); // Displaying the list System.out.println("The list is: \n" + list); // Create an iterator for the list // using iterator() method Iterator<Integer> iter = list.iterator(); // Displaying the values // after iterating through the list System.out.println("\nThe iterator values" + " of list are: "); while (iter.hasNext()) { System.out.print(iter.next() + " "); } } } Output: The list is: [10, 15, 30, 20, 5] The iterator values of list are: 10 15 30 20 5 Comment More infoAdvertise with us Next Article ArrayList iterator() method in Java with Examples 29AjayKumar Follow Improve Article Tags : Java Technical Scripter Technical Scripter 2018 Java-Collections Java-Functions Java-ArrayList +2 More Practice Tags : JavaJava-Collections Similar Reads 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. Synt 2 min read AbsractCollection iterator() Method in Java with Examples The iterator() method of Java AbstractCollection is used to return an iterator of the same elements as that of the Collection. The elements are returned in random order from what was present in the Collection. Syntax: Iterator iterate_value = AbstractCollection.iterator(); Parameters: The function d 2 min read Set iterator() method in Java with Examples The java.util.Set.iterator() method is used to return an iterator of the same elements as the set. The elements are returned in random order from what present in the set. Syntax: Iterator iterate_value = Set.iterator(); Parameters: The function does not take any parameter. Return Value: The method i 1 min read DelayQueue iterator() method in Java with Examples The iterator() method of DelayQueue is used to return an iterator over all the elements in the DelayQueue. These elements can be expired or unexpired.Syntax: public Iterator iterator () Parameters: This method does not accept any parameter.Returns: This method returns an iterator over elements in th 2 min read Path iterator() method in Java with Examples The iterator() method of java.nio.file.Path used to returns an iterator of the name elements which construct this path. The first element of this iterator contains the name element that is closest to the root in the directory hierarchy, the second element is the next closest, and so on. The last ele 2 min read BlockingDeque iterator() method in Java with examples The iterator() method of BlockingDeque returns an iterator over the elements in this deque in a proper sequence. The elements will be returned in order from first (head) to last (tail). The returned iterator is a "weakly consistent" iterator. Syntax: public Iterator iterator() Parameters: This metho 2 min read Vector iterator() method in Java with Examples iterator() method of Vector class that is present inside java.util package is used to return an iterator of the same elements as that of the Vector. The elements are returned in random order from what was present in the vector. Syntax: Iterator iterate_value = Vector.iterator(); Parameters: The func 2 min read Stack iterator() method in Java with Example The Java.util.Stack.iterator() method is used to return an iterator of the same elements as that of the Stack. The elements are returned in random order from what was present in the stack. Syntax: Iterator iterate_value = Stack.iterator(); Parameters: The function does not take any parameter. Return 2 min read SortedSet iterator() method in Java with Examples The java.util.SortedSet.iterator() method is used to return an iterator of the same elements as the set. The elements are returned in random order from what present in the set. Syntax: Iterator iterate_value = sortedSetInstance.iterator(); Parameters: The function does not take any parameter. Return 1 min read AbstractList listIterator() Method in Java with Examples The listIterator() method of java.util.AbstractList class is used to return a list-iterator containing the same elements as that of the AbstractList in proper and same sequence starting from a specific position or index number which is passed as a parameter to this method. Syntax: ListIterator new_l 2 min read Like