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 |
[ 0 ] Comments