4

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

andersoj
  • 22,406
  • 7
  • 62
  • 73
Ravi Parmar
  • 1,392
  • 5
  • 24
  • 46
  • Duplicate, see http://stackoverflow.com/questions/4456280/need-help-mapping-this-data-in-java/4456312#4456312 – andersoj Dec 16 '10 at 05:13
  • Got Similar error when using TF 1 ```tf.contrib.lookup.index_table_from_file(vocabulary_file="vocab_file.txt")```. Error was ```FailedPreconditionError: HashTable has different value for same key.``` The issue was input Vocab_file.txt had duplicate data. – sakeesh Aug 26 '21 at 04:14

2 Answers2

8

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

The Scrum Meister
  • 29,681
  • 8
  • 66
  • 64
  • Yes, and a search of SO with tag multimap reveals a lot of insight on this. http://stackoverflow.com/questions/tagged/multimap?sort=votes&pagesize=50 – andersoj Dec 16 '10 at 05:17
1

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

Jan Málek
  • 531
  • 8
  • 21
gmhk
  • 15,598
  • 27
  • 89
  • 112