Java Collection Tutorial - Java TreeSet.remove(Object o)








Syntax

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

public boolean remove(Object o)

Example

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

/*from  ww  w . j a va 2s  .  c o  m*/
import java.util.TreeSet;

public class Main {
   public static void main(String[] args) {
      
      TreeSet<Integer> treeadd = new TreeSet<Integer> ();
     
      treeadd.add(1);
      treeadd.add(3);
      treeadd.add(17);
      treeadd.add(2);
     
      System.out.println("Remove 17: "+treeadd.remove(17));      
   }     
}

The code above generates the following result.