区别对比一(HashMap 和 HashTable 区别):
1. HashMap 是非线程安全,HashTable是线程安全
2. HashMap的值和键都可以为null,而HashTable的都不可以。
3.HashMap的效率高于HashTable因为线性安全问题。
4. HashTable是同步的,HashMap不是,所以HashMap适合单线程,HashTable适合多线程,但是由于HashTable内部优化不好也不会使用它作为多线程使用。
区别对比二(HashTable 和 ConcurrentHashMap 区别):
HashTable 使用的是 Synchronized 关键字修饰,ConcurrentHashMap 是 JDK1.7 使用了锁分段技术来保证线程安全的。JDK1.8,采用CAS和synchronized来保证并发安全。数据结构跟HashMap1.8 的结构类似,数组+链表/红黑二叉树。synchronized 只锁定当前链表或红黑二叉树的首节点,这样只要hash不冲突,就 不会产生并发,效率又提升N倍。