IterateThrough Element Using Iterator Java LinkedList

IterateThrough Element Using Iterator Java LinkedList


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

This Java Example shows how to Iterate through the element of the LinkedList object in java.

IterateThrough Element Using Iterator Java LinkedList Example

This Java Example shows how to Iterate through the element of the LinkedList object in java. To iterate the LinkedList object we use hasNext() and next() methods of Iterator to iterate through the elements


Example: IterateThroughElementLinkedList.java

package devmanuals.com;

import java.util.*;

public class IterateThroughElementLinkedList {
	public static void main(String[] args) {
		LinkedList LKLST = new LinkedList();
		LKLST.add("Gyan");
		LKLST.add("Singh");
		LKLST.add("Arunesh");
		LKLST.add("Kumar");
		Iterator itr = LKLST.iterator();
		System.out.println("The LinkedList Elements are : ");
		while (itr.hasNext()) {
			System.out.println(itr.next());
		}
	}
}

Output:

The LinkedList Elements are : 

Gyan 

Singh 

Arunesh 

Kumar

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics