3:06 pm - Tuesday September 26, 2873

Check whether LinkedHashSet is empty using boolean isEmpty()

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 boolean isEmpty() checks whether the linkedhashset is empty or not. It returns true if the set contains no elements, otherwise it returns false.

Example Program


import java.util.LinkedHashSet;

public class LinkedHashSetEmpty

{

	public static void main(String[] args)

	{

		LinkedHashSet lh = new LinkedHashSet();

		lh.add(25);

		lh.add(10);

		lh.add(20);

		lh.add(35);

		boolean val = lh.isEmpty();

		if (val == true) 
		{

			System.out.println("list is empty");

		}

		else 
		{

			System.out.println("list is not empty");

		}

		System.out.println("The set is:" + lh);

	}

}

Output

   list is not empty

   The set is:[25, 10, 20, 35]

 

BACK

Filed in: Java Examples

Comments are closed.