HashMap和字典ADT之间的区别

时间:2023-01-21 16:44:09

What is the difference between a Hash Map and dictionary ADT. And when to prefer one over another. For my programming assignment my instructor has asked to use one of them but I don't see any difference in between both. The program is supposed to work with a huge no. of strings. Any suggestions?

哈希映射和字典ADT之间有什么区别。什么时候比较喜欢一个。对于我的编程作业,我的导师要求使用其中一个,但我发现两者之间没有任何区别。该计划应该与一个巨大的没有。字符串。有什么建议么?

4 个解决方案

#1


50  

In terms of Java, both the class HashMap and the class Dictionary are implementations of the "Map" abstract data type. Abstract data types are not specific to any one programming language, and the Map ADT can also be known as a Hash, or a Dictionary, or an Associative Array (others at http://en.wikipedia.org/wiki/Associative_array). (Notice we're making a distinction between the Dictionary class and the Dictionary ADT.)

就Java而言,类HashMap和类Dictionary都是“Map”抽象数据类型的实现。抽象数据类型并非特定于任何一种编程语言,并且Map ADT也可称为哈希,字典或关联数组(其他人在http://en.wikipedia.org/wiki/Associative_array)。 (注意我们在Dictionary类和Dictionary ADT之间做了区分。)

The Dictionary class has been marked as obsolete, so it's best not to use it.

Dictionary类已被标记为已过时,因此最好不要使用它。

#2


14  

This Stack Overflow post does a good job explaining the key differences:

这个Stack Overflow帖子很好地解释了关键的区别:

Java hashmap vs hashtable

Java hashmap vs hashtable

Note that Hashtable is simply an implementation of the Dictionary ADT. Also note that Java considers Dictionary "obsolete".

请注意,Hashtable只是Dictionary ADT的一个实现。另请注意,Java认为Dictionary“已过时”。

The fact that Hashtable is synchronized doesn't buy you much for most uses. Use HashMap.

Hashtable同步这一事实并不能为大多数用途带来太多收益。使用HashMap。

#3


8  

In Java the HashMap implements the Map interface while the Dictionary does not. That makes the Dictionary obsolete (according to the API docs). That is, they both do a similar function so you are right that they seem very similar...a HashMap is a type of dictionary.

在Java中,HashMap实现了Map接口,而Dictionary则没有。这使得字典过时(根据API文档)。也就是说,它们都执行类似的功能,因此你看起来非常相似...... HashMap是一种字典。

You are advised to use the HashMap though.

建议您使用HashMap。

#4


0  

Map is an interface for an ADT in Java, the same general language-independent data structure for maintaining <key, value> pairs, and is introduced in Java 1.2.

Map是Java中ADT的接口,与用于维护 对的通用语言无关的数据结构相同,并在Java 1.2中引入。 ,value>

Dictionary (not an implementation of Map) is an Abstract class for the same purpose introduced earlier in JDK 1.0. The only subclass it has is Hashtable which itself is implementing Map. Nevertheless, Dictionary class is obsolete now and you may forget it.

Dictionary(不是Map的实现)是一个Abstract类,用于JDK 1.0中之前介绍的相同目的。它拥有的唯一子类是Hashtable,它本身正在实现Map。尽管如此,Dictionary类现在已经过时了,你可能会忘记它。

There are differences between the function members of Map and Dictionary, however you may find the difference between HashMap and Hashtable more useful. here you can find the differences.

Map和Dictionary的函数成员之间存在差异,但是您可能会发现HashMap和Hashtable之间的区别更加有用。在这里你可以找到差异。

#1


50  

In terms of Java, both the class HashMap and the class Dictionary are implementations of the "Map" abstract data type. Abstract data types are not specific to any one programming language, and the Map ADT can also be known as a Hash, or a Dictionary, or an Associative Array (others at http://en.wikipedia.org/wiki/Associative_array). (Notice we're making a distinction between the Dictionary class and the Dictionary ADT.)

就Java而言,类HashMap和类Dictionary都是“Map”抽象数据类型的实现。抽象数据类型并非特定于任何一种编程语言,并且Map ADT也可称为哈希,字典或关联数组(其他人在http://en.wikipedia.org/wiki/Associative_array)。 (注意我们在Dictionary类和Dictionary ADT之间做了区分。)

The Dictionary class has been marked as obsolete, so it's best not to use it.

Dictionary类已被标记为已过时,因此最好不要使用它。

#2


14  

This Stack Overflow post does a good job explaining the key differences:

这个Stack Overflow帖子很好地解释了关键的区别:

Java hashmap vs hashtable

Java hashmap vs hashtable

Note that Hashtable is simply an implementation of the Dictionary ADT. Also note that Java considers Dictionary "obsolete".

请注意,Hashtable只是Dictionary ADT的一个实现。另请注意,Java认为Dictionary“已过时”。

The fact that Hashtable is synchronized doesn't buy you much for most uses. Use HashMap.

Hashtable同步这一事实并不能为大多数用途带来太多收益。使用HashMap。

#3


8  

In Java the HashMap implements the Map interface while the Dictionary does not. That makes the Dictionary obsolete (according to the API docs). That is, they both do a similar function so you are right that they seem very similar...a HashMap is a type of dictionary.

在Java中,HashMap实现了Map接口,而Dictionary则没有。这使得字典过时(根据API文档)。也就是说,它们都执行类似的功能,因此你看起来非常相似...... HashMap是一种字典。

You are advised to use the HashMap though.

建议您使用HashMap。

#4


0  

Map is an interface for an ADT in Java, the same general language-independent data structure for maintaining <key, value> pairs, and is introduced in Java 1.2.

Map是Java中ADT的接口,与用于维护 对的通用语言无关的数据结构相同,并在Java 1.2中引入。 ,value>

Dictionary (not an implementation of Map) is an Abstract class for the same purpose introduced earlier in JDK 1.0. The only subclass it has is Hashtable which itself is implementing Map. Nevertheless, Dictionary class is obsolete now and you may forget it.

Dictionary(不是Map的实现)是一个Abstract类,用于JDK 1.0中之前介绍的相同目的。它拥有的唯一子类是Hashtable,它本身正在实现Map。尽管如此,Dictionary类现在已经过时了,你可能会忘记它。

There are differences between the function members of Map and Dictionary, however you may find the difference between HashMap and Hashtable more useful. here you can find the differences.

Map和Dictionary的函数成员之间存在差异,但是您可能会发现HashMap和Hashtable之间的区别更加有用。在这里你可以找到差异。