/** * Returns a new {@code Hashtable} with the same key/value pairs, capacity and load factor. * * @return a shallow copy of this {@code Hashtable}. * @see java.lang.Cloneable */ @SuppressWarnings("unchecked") @Override public synchronized Object clone() { /* * This could be made more efficient. It unnecessarily hashes all of * the elements in the map. */ Hashtable<K, V> result; try { result = (Hashtable<K, V>) super.clone(); } catch (CloneNotSupportedException e) { throw new AssertionError(e); } // Restore clone to empty state, retaining our capacity and threshold result.makeTable(table.length); result.size = 0; result.keySet = null; result.entrySet = null; result.values = null; result.constructorPutAll(this); return result; }
/** * Constructs a new instance of {@code Hashtable} containing the mappings from the specified map. * * @param map the mappings to add. */ public Hashtable(Map<? extends K, ? extends V> map) { this(capacityForInitSize(map.size())); constructorPutAll(map); }