HashMap与HashTable的区别是什么?分别在什么情况下选用?

解决方案 »

  1.   

    除非是处于对老版本JVM的兼容一般推荐用HashMap
    如果需要线程安全的话直接用Collections.synchronizedMap处理一个
      

  2.   

    楼上正解
    HashTable已经过时了
      

  3.   

    Thinking in java 里面的一段话:
    As you might expect, Hashtable performance is roughly equivalent to HashMap. (You can also see that HashMap is generally a bit faster. HashMap is intended to replace Hashtable.)
      

  4.   

    还有一个区别就是
    HashMap可以接受key的值为null,而Hashtable则不行
      

  5.   

    他们两个都能实现统一的map接口 HashMap的最基本的区别是能够实现一个null key对应若干null value. 这个在hashtable 是不被允许的
      

  6.   

    功能上,HashMap可以接受空值,HashTable不行;性能上,基本相同;发展商,HashMap是HashTable的替换版本,后继版本中HanshTable可能会deprecated