How to remove the specific element from the TreeSet

How to remove the specific element from the TreeSet

Previous Home Next

 

This example will shows how to remove the particular element from the TreeSet.

Remove() method of TreeSet is used to remove the particular element from the TreeSet.
 remove()  method will remove the element from the TreeSet and will return the true.if specific element exists in the TreeSet.


 

package Example;

import java.util.Iterator;
import java.util.TreeSet;
import java.util.SortedSet;

public class TreeSetSubSet {

/**
* @param args
*/
/**
* @param args
*/
public static void main(String[] args) {
TreeSet Tst =new TreeSet();
Tst.add(new Integer("10"));
Tst.add(new Integer("17"));
Tst.add(new Integer("15"));
Tst.add(new Integer("19"));
Tst.add(new Integer("12"));
Tst.add(new Integer("13"));

boolean sortedSet = Tst.remove(new Integer ("17"));

System.out.println("Tail set Contains : " + sortedSet);
System.out.println(" The elements after removal are:" + Tst);
// TODO Auto-generated method stub

}

}

The element is remove from the TreeSet : true
 The elements after removal are:[10, 12, 13, 15, 19]

Previous Home Next