【问题标题】:Running time of HashTable Operations vs HashMap operations?HashTable 操作与 HashMap 操作的运行时间?
【发布时间】:2012-02-15 20:46:02
【问题描述】:

HashTable 和 HashMap 上的常用操作(get、put、size)的运行时间(Big O notaton)是多少,有区别吗?

【问题讨论】:

    标签: java hashmap hashtable


    【解决方案1】:

    HashtableHashMap 的渐近线没有区别,它们是 put 的可预测的预期摊销 O(1)O(1) 的预期摊销 get,假设你有一个好的哈希函数。

    最大的不同是Hashtable 会产生无偿的开销来同步来自并发线程的访问,a) 你通常不需要,b) 由ConcurrentHashMap 更有效地完成。您基本上不应该在新代码中使用Hashtable

    【讨论】:

      猜你喜欢
      • 2015-12-04
      • 1970-01-01
      • 2011-03-27
      • 1970-01-01
      • 2011-01-10
      • 2011-11-30
      • 2018-04-28
      • 1970-01-01
      • 2013-08-27
      相关资源
      最近更新 更多