Check if a particular value exists in TreeSet - Java Collection Framework

Java examples for Collection Framework:TreeSet

Description

Check if a particular value exists in TreeSet

Demo Code

 
import java.util.TreeSet;
 
public class Main {
 
  public static void main(String[] args) {
    TreeSet tSet = new TreeSet();
   /*  w ww . j av  a  2 s  . co m*/
    tSet.add("1");
    tSet.add("3");
    tSet.add("2");
    tSet.add("5");
    tSet.add("4");
   
    boolean blnExists = tSet.contains("3");
    System.out.println("3 exists in TreeSet ? : " + blnExists);
  }
}

Result


Related Tutorials