How to remove all the elements from the TreeSet
Previous | Home | Next |
This example will shows us how to remove all the elements from the TreeSet.
TreeSet class of java has a method public Boolean removeall collection(c). this remove all the elements from the TreeSet.and will return result in true.
The public boolean Removeall collection (c) will return the result in true .if all the elements will remove otherwise it will throw UnsupportedOpereationException.
package Example;
import java.util.Iterator;
import java.util.TreeSet;
import java.util.SortedSet;
public class RemoveallElementTreeSet {
/**
* @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"));
System.out.println(" The elements of the TreeSet before removal are:" +Tst);
boolean sortedSet = Tst.removeAll(Tst);
System.out.println(" After removal:" +sortedSet);
// TODO Auto-generated method stub
}
}
The elements of the TreeSet before removal are:[10, 12, 13, 15, 17, 19]
After removal:true
Previous | Home | Next |