Stack listIterator() method in Java with Example
The listIterator() method of Java.util.Stack class is used to return a list iterator over the elements in this stack (in proper sequence). The returned list iterator is fail-fast.
public ListIterator listIterator()
Return Value: This method returns a list iterator over the elements in this stack (in proper sequence).
Below are the examples to illustrate the listIterator() method.
Stack: [A, B, C, D] Using ListIterator: Value is : A Value is : B Value is : C Value is : D
Stack: [1, 2, 3, 10, 20] Using ListIterator: Value is : 1 Value is : 2 Value is : 3 Value is : 10 Value is : 20
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.