Remove specified element from TreeSet - Java Collection Framework

Java examples for Collection Framework:TreeSet

Description

Remove specified element from TreeSet

Demo Code


import java.util.TreeSet;
 
public class Main {
 
  public static void main(String[] args) {
    //create object of TreeSet
    TreeSet tSet = new TreeSet();
   //from   w  ww .ja v a  2s.  c  o m
    //add elements to TreeSet object
    tSet.add(new Integer("1"));
    tSet.add(new Integer("2"));
    tSet.add(new Integer("3"));
   
    System.out.println("TreeSet before removal : " + tSet);
   
    boolean blnRemoved = tSet.remove(new Integer("2"));
    System.out.println("Was 2 removed from TreeSet ? " + blnRemoved);
   
    System.out.println("TreeSet after removal : " + tSet);
  }
}
 

Result


Related Tutorials