1 16 package java.util; 17 18 21 public class HashSet extends AbstractSet implements Set , Cloneable { 22 23 private transient HashMap map; 24 25 public HashSet() { 26 map = new HashMap (); 27 } 28 29 public HashSet(Collection c) { 30 map = new HashMap (c.size()); 31 addAll(c); 32 } 33 34 public HashSet(int initialCapacity) { 35 map = new HashMap (initialCapacity); 36 } 37 38 public HashSet(int initialCapacity, float loadFactor) { 39 map = new HashMap (initialCapacity, loadFactor); 40 } 41 42 public boolean add(Object o) { 43 Object old = map.put(o, Boolean.valueOf(true)); 44 return (old == null); 45 } 46 47 public void clear() { 48 map.clear(); 49 } 50 51 public Object clone() { 52 return new HashSet (this); 53 } 54 55 public boolean contains(Object o) { 56 return map.containsKey(o); 57 } 58 59 public boolean isEmpty() { 60 return map.isEmpty(); 61 } 62 63 public Iterator iterator() { 64 return map.keySet().iterator(); 65 } 66 67 public boolean remove(Object o) { 68 return (map.remove(o) != null); 69 } 70 71 public int size() { 72 return map.size(); 73 } 74 75 public String toString() { 76 return map.keySet().toString(); 77 } 78 79 } 80 | Popular Tags |