Java 哈希表相同的键具有不同的值....?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4457623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 17:47:59  来源:igfitidea点击:

Hashtable same Key with different value....?

javamultimap

提问by Ravi Parmar

Is it possible with java that a hashtable can map the same keys to different values? .. How can I retrieve both value from hashtable...

java 是否有可能将哈希表映射到不同的值?.. 如何从哈希表中检索两个值...

采纳答案by The Scrum Meister

you cannot, unless you store the key's value as a list of values.

您不能,除非您将键的值存储为值列表。

take a look at google's Multimap: http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/Multimap.html

看看谷歌的 Multimap:http: //google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/Multimap.html

回答by gmhk

You cant do that, All the keys in the Hash map or Hash Table should be unique.

你不能这样做,哈希映射或哈希表中的所有键都应该是唯一的。

Else then you need to consider a different Collection

否则你需要考虑一个不同的集合