JAVA菜鸟入门(5) Hashmap vs Hashtable

1. Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.


2. Hashtable does not allow null keys or values.  HashMap allows one null key and any number of null values.


3. One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.


4. Java 5提供了ConcurrentHashMap,它是HashTable的替代,比HashTable的扩展性更好。

5. "hashmap allows a null key(only one is allowed) and many null values"

这里的null value很好理解,但是null key我貌似没咋见过。google之, 找到一个很生动的例子 ,如下:

"

One real life scenario where even a "null" can convey information.
I am working on a project where I have "jobs" (e.g. copy some data from some place to another). I also have a "schedule" which can be associated to the "jobs". The "schedule" contains information on at what time the job should be executed and when should it be repeated. 
There is a simple check which we have put in. If the job schedule is null, we execute the job only once. Else we execute it as per schedule. 

"

6.  note that if a HashMap is modified, iterators pointing to it are rendered invalid.




参考链接:

http://www.coderanch.com/t/385836/java/java/HashMap-add-NULL-key

http://www.importnew.com/7010.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值