Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 86ba4ae

Browse files
committed
differences-between-hashmap-and-hashtable.md
1 parent 48347af commit 86ba4ae

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## HashMap和Hashtable的区别
2+
### 问题
3+
在Java中`HashMap``Hashtable`的区别?
4+
哪一个对于非线程应用程序更有效?
5+
6+
### 回答
7+
1. `Hashtable`是同步的,而`HashMap`不是。这让`HashMap`对于非线程应用程序来说更加好一点,对于非同步对象通常表现得比同步的要好。
8+
2. `Hashtable`不允许有空的键或值。`HashMap`允许空的键和任何数值的空值。
9+
3. HashMap的一个子类是[LinkedHashMap](http://docs.oracle.com/javase/7/docs/api/java/util/LinkedHashMap.html),如果你想预知迭代的顺序(插入的时候就自动排序了),你能轻易的从`LinkedHashMap`转化成`HashMap`。对于`Hashtable`就不那么容易。
10+
如果同步对于你不是那么重要的话,我会建议用`HashMap`.如果同步很重要的话,你可以看看[ConcurrentHashMap](http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ConcurrentHashMap.html)
11+
12+
### stackoverflow链接:
13+
http://stackoverflow.com/questions/40471/differences-between-hashmap-and-hashtable
14+
15+
### 相关推荐:
16+
importnew:[HashMap和Hashtable的区别](http://www.importnew.com/7010.html)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /