Code:
HashSetRemoveElement.java
|
package net.roseindia;import java.util.HashSet; public class RemoveAllElement { public static void main(String[] arg) {HashSet obHashSet = new HashSet();obHashSet.add( new Integer(1));obHashSet.add( new Integer(2));obHashSet.add( new Integer(3));obHashSet.add( new Integer(4));System. out.println("Element before clear method : " + obHashSet);obHashSet.clear(); System. out.println("Check HashSet : " + obHashSet.isEmpty());System. out.println("Element after clear method : " + obHashSet);} } |
|
Element before clear method : [1, 2, 3, 4] Check HashSet : true Element after clear method : [] |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.