Java TreeSet.contains(Object o)

Syntax

TreeSet.contains(Object o) has the following syntax.

public boolean contains(Object o)

Example

In the following code shows how to use TreeSet.contains(Object o) method.


//  ww  w  .  ja v  a  2 s . c  o m
import java.util.Iterator;
import java.util.TreeSet;

public class Main {
   public static void main(String[] args) {
     
     TreeSet <Integer> treeadd = new TreeSet<Integer> ();
     
     treeadd.add(12);
     treeadd.add(13);
     treeadd.add(14);
     treeadd.add(15);
     
     // check existence of 15  
     System.out.println("Checking existence of 15 ");
     System.out.println("Is 15 there in the set: "+treeadd.contains(15));
   }    
}

The code above generates the following result.