IterateThrough Element Using ListIterator Java LinkedList

IterateThrough Element Using ListIterator Java LinkedList


Posted in : Java Posted on : November 30, 2010 at 5:50 PM Comments : [ 0 ]

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 elementsListIterator 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 :
Kumar
Arunesh
Singh
Gyan

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics