Java HashSet Remove All Elements
Chapter:
Collections
Last Updated:
10-05-2016 19:48:18 UTC
Program:
/* ............... START ............... */
import java.util.HashSet;
public class JavaHashSetRemoveAllElements {
public static void main(String[] args) {
// create object of HashSet
HashSet hashSet = new HashSet();
// add elements to HashSet object
hashSet.add(new Integer("1"));
hashSet.add(new Integer("2"));
hashSet.add(new Integer("3"));
System.out.println("HashSet before removal : " + hashSet);
hashSet.clear();
System.out.println("HashSet after removal : " + hashSet);
System.out.println("Is HashSet empty ? " + hashSet.isEmpty());
}
}
/* ............... END ............... */
Output
HashSet before removal : [1, 2, 3]
HashSet after removal : []
Is HashSet empty ? true
Tags
Collection, HashSet Remove All Elements, Java