3:33 am - Saturday August 19, 2017

Iterate LinkedHashSet elements using Iterator iterator()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

                            The method public Iterator<E> iterator(), iterates the elements in the linkedhashset using while(it.hasNext()).The elements are returned without a particular order.

 

Example Program


import java.util.Iterator;

import java.util.LinkedHashSet;

public class LinkedHashSetiterator

{

	public static void main(String[] args) 
	
	{

		LinkedHashSet linkedHashSet = new LinkedHashSet();

		linkedHashSet.add("Add");

		linkedHashSet.add("Sub");

		linkedHashSet.add("Mul");

		Iterator it = linkedHashSet.iterator();

		System.out.println("Elements in LinkedHashSet :");

		while (it.hasNext())

			System.out.println(it.next());

    	}

}


Output

   Elements in LinkedHashSet :

    Add

    Sub

    Mul

 

BACK

Filed in: Java Examples

Comments are closed.