Does HashMap.clear () resize the original size?
2 answers
This is an implementation detail, and I don't know which API you are reading that says anything about 1M puts or the internal hash table.
Let's take a look at the implementation:
620 /**
621 * Removes all of the mappings from this map.
622 * The map will be empty after this call returns.
623 */
624 public void clear() {
625 modCount++;
626 Entry[] tab = table;
627 for (int i = 0; i < tab.length; i++)
628 tab[i] = null;
629 size = 0;
630 }
http://www.docjar.com/html/api/java/util/HashMap.java.html#621
Thus, the OpenJDK 7 implementation does not restore its original size.
+2
source to share