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,575
  • 7
  • 41
  • 48
mechanikos
  • 771
  • 12
  • 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
  • 22,183
  • 20
  • 145
  • 196
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,561
  • 4
  • 45
  • 63