Remove all elements from a set in Java
Description
The following code shows how to remove all elements from a set.
Example
/*from w ww . j a v a 2 s .c o m*/
import java.util.HashSet;
import java.util.Set;
public class Main {
public static void main(String[] argv) throws Exception {
Set set1 = new HashSet();
set1.add('A');
set1.add('B');
set1.add('C');
set1.add('D');
System.out.println(set1);
set1.clear();
System.out.println(set1);
}
}
The code above generates the following result.