3:11 pm - Tuesday November 25, 8808

Clear elements from LinkedHashSet using void clear()

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

                     This tutorial explains how  to Clear elements from LinkedHashSet using void clear() method.

Example Program


import java.util.LinkedHashSet;

public class LinkedHashSetclear 

{

	public static void main(String[] args) 
	
	{

		LinkedHashSet<Integer> lh = new LinkedHashSet<Integer>();

		lh.add(20);

		lh.add(30);

		lh.add(10);

		lh.add(50);

		for (Integer number : lh) 
		{

			System.out.println("Number = " + number);

		}

		int val = lh.size();

		System.out.println("set consists of " + val + " elements");

		System.out.println("Perform clear operation !!");

		lh.clear();

		val = lh.size();

		System.out.println("set consists of " + val + " elements");

	}

}


Output

   Number = 20

   Number = 30

   Number = 10

   Number = 50

   set consists of 4 elements

   Perform clear operation !!

   set consists of 0 elements

BACK

Filed in: Java Examples

Comments are closed.