This Java Example shows how to Iterate through the element of the LinkedList object in java using ListIterator.
IterateThrough Element Using ListIterator Java LinkedList Example
This Java Example shows how to Iterate through the element of the LinkedList object in java using ListIterator. To iterate the LinkedList object we use hasNext() , next(), hasPrivious() and privious() methods of ListIterator to iterate through the elements. ListIterator iterate through element in the both farword and backword direction.
Example: ListIteratorIterateLinkedList.java
package devmanuals.com;
import java.util.*;
public class ListIteratorIterateLinkedList {
public static void main(String[] args) {
LinkedList LKLST = new LinkedList();
LKLST.add("Gyan");
LKLST.add("Singh");
LKLST.add("Arunesh");
LKLST.add("Kumar");
ListIterator itr = LKLST.listIterator();
System.out.println("The LinkedList Elements in farword direction : ");
while (itr.hasNext()) {
System.out.println(itr.next());
}
System.out.println("The LinkedList Elements in backword direction : ");
while (itr.hasPrevious()) {
System.out.println(itr.previous());
}
}
}
Output:
| The LinkedList Elements in farword direction : Gyan Singh Arunesh Kumar
The LinkedList Elements in backword direction : |

[ 0 ] Comments