TreeSet remove Example
TreeSet class remove example. This example shows you how to use remove method.
TreeSet class remove example.public boolean remove(Object o) Removes the specified element from this set if it is present. More formally, removes an element e such that (o==null ? e==null : o.equals(e)), if this set contains such an element
Here is the code
/**
* @ # Remove.java
* A class repersenting use to Remove method
* of TreeSet class in java.util package
* version 23 May 2008
* author Rose India
*/
import java.util.*;
public class Remove {
public static void main(String args[]) {
TreeSet ts = new TreeSet();
// Add the elements to the set and display it:
System.out.println("Element is added :" + ts.add(10));
System.out.println("Element is added :" + ts.add(20));
System.out.println("Element is added :" + ts.add(15));
System.out.println("All element of the TreeSet " + ts);
ts.remove(15);
System.out.println("All element of the TreeSet " + ts);
}
} |
Output
Element is added :true
Element is added :true
Element is added :true
All element of the TreeSet [10, 15, 20]
All element of the TreeSet [10, 20] |
|