- 阅读权限
- 255
- 威望
- 0 级
- 论坛币
- 49957 个
- 通用积分
- 79.5487
- 学术水平
- 253 点
- 热心指数
- 300 点
- 信用等级
- 208 点
- 经验
- 41518 点
- 帖子
- 3256
- 精华
- 14
- 在线时间
- 766 小时
- 注册时间
- 2006-5-4
- 最后登录
- 2022-11-6
|
What are the differences between a HashMap and a Hashtable in Java?
- Solution
- There are several differences between HashMap
- and Hashtable in Java:
- 1. Hashtable is synchronized, whereas HashMap is
- not. This makes HashMap better for nonthreaded
- 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.
- Since synchronization is not an issue for you,
- I'd recommend HashMap. If synchronization
- becomes an issue, you may also look at
- ConcurrentHashMap.
复制代码
|
|