Check value is exists In Java TreeSet Example

Check value is exists In Java TreeSet Example


Posted in : Java Posted on : November 24, 2010 at 5:18 PM Comments : [ 0 ]

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

Check value is exists In Java TreeSet Example

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

Example:- CheckValueInTreeSet.java

package devmanuals.com;

import java.util.*;

public class CheckValueInTreeSet {

	public static void main(String[] args) {

		TreeSet st = new TreeSet();

		st.add("Gyan");
		st.add("Rohit");
		st.add("Anand");
		st.add("Arunesh");

		boolean bl=st.contains("Gyan");
		System.out.println("Is Gyan exists? :" +bl);
		
	}
}

Output:-

Is Gyan exists? :true

Download The Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics