For general cases, when one of them will work, which is better to use, a hash map or a hash table?

I sometimes used hash tables in several languages, but I just stumbled upon a Java map while looking at some code. I checked the differences in this SO question , which expressed this very clearly. My question is this:

  • When anyone can work for you, which is better to use? Which one to choose if you are not working with zeros / threads ...?

  • Which one is more commonly used / is more standard?

+3
source share
6 answers
  • , HashMap, , Hashtable
  • , HashMap . Hashtable concurrency .
+7

Hashtable . JDK 1.0. 1.2, , Hashtable , . , ​​ ( , , YMMV).

, , Hashtable, . , HashMap . , "null null" .

StringBuffer, StringBuilder.

, : HashMap: . Hashtable - . , Hashtable Collections.synchronizedMap().

+5

HashMap, .

+1

HashMap, Hashtable , , .

+1

Hashtable Java, HashMap Framework Collections, Java 2. :

  • Hashtable , HashMap - . , .

a HashMap , Hashtable - .

a HashMapallows zero values ​​in it, but Hashtablenot.

So you can go with HashMapfor any new code. If you need synchronization, you better off Collections.synchronizedMap(HashMap). See this similar SO threa d for more ideas.

0
source

HashMap for local variables or method parameters, since they are thread safe.

-2
source

Source: https://habr.com/ru/post/1732910/


All Articles