https://www.youtube.com/watch?v=UTGW0AtMBK4&list=UUhwKlOVR041tngjerWxVccw
HashSetExample.java
Output
HashSetExample.java
import java.util.HashSet; /* * Example of add(E e) method. */ public class HashSetExample { public static void main( String[] args ) { HashSet<String> hashSet = new HashSet<String>(); System.out.println("hashSet: " + hashSet + "\n"); /* * Adds the specified element to this set if it is not already present. * * If this set already contains the element, the call leaves the set * unchanged and returns false. */ boolean isAdded = hashSet.add("Dave"); System.out.println("isAdded : " + isAdded); System.out.println("hashSet: " + hashSet + "\n"); isAdded = hashSet.add("Dave"); System.out.println("isAdded : " + isAdded); System.out.println("hashSet: " + hashSet); } }
hashSet: [] isAdded : true hashSet: [Dave] isAdded : false hashSet: [Dave]
https://sites.google.com/site/javaee4321/java-collections/HashSetDemoAdd.zip?attredirects=0&d=1
See also:
No comments:
Post a Comment