I am trying to find a data structure that takes in a particular value from a range of values and map it to a key.
For example, I have the following conditions:
- From 1 to 2.9, I want to map it to A.
- From 4 to 6, I want to map it to B.
- From 6.5 to 10, I want to map it to C.
I have a value of 5 and I would like to map it to a key. So based on the above conditions, I should map it to B.
Is there any data structure in Java that anyone can recommend to me to solve the problem?
Currently I am using a hashtable that can only map a value to a key. I tried to map the range of values to a particular value that exists in the hashtable. However, I got stuck in the mapping of the range of values to a particular value. So now I am trying to do another way of mapping the ranges of values to a key. Does anyone have any idea how I can solve this problem?
EDIT:
Thanks to Martin Ellis, I decided to use TreeMap to solve the problem.