0

Tell me please, there any methods in standard library for implementation some simple dictionary look like: "a=10,b=11,c=12...". I know about HashMap, but as I know we can`t get key by value, just value by key.

Touchstone
  • 5,144
  • 7
  • 38
  • 48
mechanikos
  • 761
  • 9
  • 32

2 Answers2

2

if key & value are all identify, and 1 to 1, then you can write a class which have 2 Map,
1 Map store key:value, another store value:key, so that you can do search in both way.

Also, if key & value have fixed relationship which could be convert by a function, then you can use that function to convert key & value to each other.

Eric
  • 19,030
  • 16
  • 132
  • 171
1

Take a look at Guava BiMap. Seems what you're looking for.

http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/BiMap.html

Andres
  • 10,181
  • 4
  • 40
  • 61