HashMap与HashTable的区别
来源:互联网 发布:ubuntu jdk安装 编辑:程序博客网 时间:2024/06/03 14:19
同步与线程安全
HashMap是不同步,是非线程安全的;而HashTable是同步,是线程安全的。该区别决定了他们的使用场景。HashMap适合在单线程模式下使用,而HashTable适合在多线程模式下使用。为了解决HashMap的非线程安全问题,可以选择使用ConcurrentHashMap。该区别也决定了两者的效率:在单线程模式下,HashMap在时间和空间上都优于HashTable。
Null主键和Null值
HashMap允许有一个Null主键,和数量不等的Null值,而HashTable不允许有Null主键和Null值
遍历值的方式
HashMap通过Iterator遍历,而HashTable通过Enumerator遍历值(类似的还有vector)。HashMap的iterate是fail-fast,有可能会抛出ConcurrentModification异常;而HashTable的enumerate不是fail-fast。Iterator 与 Enumerator的区别
共同点
HashMap和HashTable都不保证元素顺序与其插入顺序一致。LinkedHashMap可以保证插入顺序的一致性。两者都实现了Map接口。两者的实现原理都是基于Hash思想。HashMap的实现原理
0 0
- HashTable与HashMap的区别
- HashMap与Hashtable的区别
- Hashtable与HashMap的区别:
- HashMap 与 Hashtable 的区别?
- HashMap与HashTable的区别
- HashMap与Hashtable的区别
- HashMap与Hashtable的区别
- HashTable与HashMap的区别
- Hashtable与HashMap的区别
- HashMap与Hashtable的区别
- HashMap与HashTable的区别?
- hashtable与hashmap的区别
- HashMap与Hashtable的区别
- HashMap与Hashtable的区别
- HashMap与Hashtable的区别
- HashMap与Hashtable的区别
- hashtable与hashmap的区别
- HashMap与Hashtable的区别
- Android 系统状态栏一体化
- Solr的部署
- spring MVC 文件执行顺序
- 稀疏表示综述:A Survey of Sparse Representation: Algorithms and Applications_2015(1)
- hdu 4084
- HashMap与HashTable的区别
- TAIL Queue数据结构
- hihoCoder 1014 Trie树 (Trie)
- ConcurrentModificationException异常总结-多线程方式
- Maven提高篇系列之——使用Profile
- Struts2之数据标签(一)
- Motion Segmentation by Velocity Clustering with Estimationof Subspace Dimension阅读报告
- leetcode系列(15)移除链表中的指定元素
- EFM8单片机与I2C外设通信