https://www.youtube.com/watch?v=WrXc2mtLEj0&list=UUhwKlOVR041tngjerWxVccw
HashSetExample.java
Output
HashSetExample.java
import java.util.HashSet; /* * Example of clear() method. */ public class HashSetExample { public static void main( String[] args ) { HashSet<String> hashSet = new HashSet<String>(); hashSet.add("Dave"); hashSet.add("Peter"); hashSet.add("Phil"); hashSet.add("Rohit"); hashSet.add("Virat"); System.out.println("hashSet: " + hashSet + "\n"); /* * Removes all of the elements from this set. The set will be empty * after this call returns. */ hashSet.clear();; System.out.println("hashSet: " + hashSet + "\n"); } }
hashSet: [Rohit, Dave, Phil, Peter, Virat] hashSet: []
https://sites.google.com/site/javaee4321/java-collections/HashSetDemoClear.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment