Remove all elements from TreeSet in Java
Description
The following code shows how to remove all elements from TreeSet.
Example
/*from www .ja v a 2 s .c o m*/
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
TreeSet<Integer> tSet = new TreeSet<Integer>();
tSet.add(new Integer("1"));
tSet.add(new Integer("2"));
tSet.add(new Integer("3"));
System.out.println("TreeSet before removal : " + tSet);
tSet.clear();
System.out.println("TreeSet after removal : " + tSet);
System.out.println("Is TreeSet empty ? " + tSet.isEmpty());
}
}
The code above generates the following result.