LoginSignup
2
2

More than 5 years have passed since last update.

[Java]Hashmap,HashTableの違い

Last updated at Posted at 2018-10-09

1、継承が違い
HashMap
image.png

HashTable

image.png

HashTable extends Dictionary
ここにHashTableの親クラスdictionaryはもう使われていない。
image.png

2、nullキーの違い
HashTableでは、nullのkeyとnullのvalueは使えない。

HashMapでは使える。

3、マルチスレッドのサポートの違い
HashTableのIFはすべてsynchronizedを追加されたため、そのままマルチスレッドの環境で動作できる。
image.png

HashMapはマルチスレッドで使うとdeadlockを発生する可能性がある。
※:それを回避するために、java1.5からConcurrentHashMapを追加された、マルチスレッド
環境では使える。

4、スピードの違い
HashMapは速い
HashTableは遅い

まとめ
一般的にHashMapを使うべき、ただマルチスレッドの場合はConcurrentHashMapを使う。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2