Map m = Collections.synchronizedMap(new HashMap(...));
HashTable can only contain non-null object as a key or as a value. HashMap can contain one null key and null values.
The iterators returned by Map are fail-fast, if the map is structurally modified at any time after the iterator is created, in any way except through the iterator's own remove method, the iterator will throw a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future. Whereas the Enumerations returned by Hashtable's keys and elements methods are not fail-fast.
HashTable and HashMap are member of the Java Collections Framework (since Java 2 platform v1.2, HashTable was retrofitted to implement the Map interface).
HashTable is considered legacy code, the documentation advise to use ConcurrentHashMap in place of Hashtable if a thread-safe highly-concurrent implementation is desired.
HashMap doesn't guarantee the order in which elements are returned. For HashTable I guess it's the same but I'm not entirely sure, I don't find ressource that clearly state that.
HashMap,Hashtable在哈希冲突的情况下,他们将映射条目存储在链表中。from Java8 forHashMap如果哈希桶的增长超过某个阈值,该桶将从linked list of entries to a balanced tree切换.这将最坏情况的性能从O(n)提高到O(log n)。当将列表转换为二叉树时,哈希码被用作分支变量。如果在同一个桶中有两个不同的哈希码,一个被认为更大,并且去树的右边,另一个去左边。但是当两个哈希码相等时,HashMap假设键是可比较的,并比较键以确定方向,以便可以维护一些顺序。使HashMap的键具有可比性是一个很好的做法