Check value is exists In Java LinkedHashSet Example

Check value is exists In Java LinkedHashSet Example


Posted in : Java Posted on : December 8, 2010 at 5:40 PM Comments : [ 0 ]

This Java Example shows how to check whether a particular value exists in LinkedHashSet or not.

Check value is exists In Java LinkedHashSet Example

This Java Example shows how to check whether a particular value exists in LinkedHashSet or not. To check whether a particular value exists in LinkedHashSet We use boolean contains(Object value) method of LinkedHashSet class.  It returns true if a specified object is an element within the collection otherwise false.

Example:- CheckValueInLinkedHashSet.java

package devmanuals.com;

import java.util.LinkedHashSet;

public class CheckValueInLinkedHashSet {
	public static void main(String args[]) {

		LinkedHashSet LHSet = new LinkedHashSet();
		LHSet.add("C");
		LHSet.add("A");
		LHSet.add("B");
		LHSet.add("E");
		LHSet.add("F");
		LHSet.add("D");
		System.out.println("The LinkedHashSet elements are: " + LHSet);
		System.out.println("Is B is exists : " + LHSet.contains("B"));
	}
}

Output:-

The LinkedHashSet elements are: [C, A, B, E, F, D] 

Is B is exists : true

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics