Java AbstractSequentialList | iterator() method
AbstractSequentialList iterator() method in Java is used to get an Iterator or List Iterator over a list. It returns an iterator over the elements in this list (in proper sequence). This method overrides iterator() in class AbstractList<E>
Syntax:
public Iterator<E> iterator()
Return Value: This method returns an iterator over the elements in this list (in proper sequence).
Below is the code to illustrate iterator() method:
Program 1:
// Java program to demonstrate // iterator() method import java.util.*; public class GfG { public static void main(String[] args) { // Creating an instance of the AbstractSequentialList AbstractSequentialList<Integer> absl = new LinkedList<>(); // adding elements to absl absl.add(5); absl.add(6); absl.add(7); absl.add(2, 8); absl.add(2, 7); absl.add(1, 9); absl.add(4, 10); // Getting Iterator Iterator<Integer> Itr = absl.iterator(); // Traversing elements with help of iterator while (Itr.hasNext()) { System.out.print(Itr.next() + " "); } } } |
5 9 6 7 10 8 7
Program 2:
// Java program to demonstrate // iterator() method import java.util.*; public class GfG { public static void main(String[] args) { // Creating an instance of the AbstractSequentialList AbstractSequentialList<String> absl = new LinkedList<>(); // adding elements to absl absl.add("Geeks"); absl.add("ForGeeks"); absl.add("A"); absl.add("Portal"); absl.add(3, "Computer Science"); absl.add(5, "For Geeks"); // Getting Iterator Iterator<String> Itr = absl.iterator(); // Traversing elements with help of iterator while (Itr.hasNext()) { System.out.println(Itr.next()); } } } |
Geeks ForGeeks A Computer Science Portal For Geeks
Recommended Posts:
- AbstractSequentialList contains() method in Java with Example
- AbstractSequentialList set() method in Java with Examples
- AbstractSequentialList removeAll() method in Java with Example
- AbstractSequentialList size() method in Java with Example
- AbstractSequentialList isEmpty() method in Java with Example
- AbstractSequentialList toString() method in Java with Example
- AbstractSequentialList get() method in Java with Examples
- AbstractSequentialList set(int, Object) method in Java with Example
- AbstractSequentialList toArray(T[]) method in Java with Example
- AbstractSequentialList retainAll() method in Java with Example
- AbstractSequentialList toArray() method in Java with Example
- AbstractSequentialList conatinsAll() method in Java with Example
- AbstractSequentialList indexOf() method in Java with Example
- AbstractSequentialList lastIndexOf() method in Java with Example
- AbstractSequentialList subList() method in Java with Example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



