Check if a particular value exists in TreeSet in Java
Description
The following code shows how to check if a particular value exists in TreeSet.
Example
import java.util.TreeSet;
//w w w . ja va 2 s . c o m
public class Main {
public static void main(String[] args) {
TreeSet<String> tSet = new TreeSet<String>();
tSet.add("1");
tSet.add("2");
tSet.add("3");
tSet.add("4");
tSet.add("5");
boolean blnExists = tSet.contains("3");
System.out.println("3 exists in TreeSet ? : " + blnExists);
}
}
The code above generates the following result.