Is it possible to obtain values that match a range of keys in Java Map. Suppose I have,
Map<Key,Value> //size 10,000
Key - 9.0, 9.1, 9.5, 4.2, 4.3, 6.1, 6.6
Value - 10 , 20 , 30 , 40 , 20 , 60 , 10
ArrayList alMatch = {1.0,4.0,6.0}
In this case, for the value 4.0 I want to get 40(key 4.2) and 20(key 4.3). So I want to get all the values mapping to the key 5.0 >= key>=4.0 in the Map. Is it possible to do this through Map or similar data structure.
The size of the map is huge. Or is there any other better way to achieve the same with minimum complexity.
You can use an implementation of NavigableMap (example TreeMap). This method in particular might interest you :
The underlying data structure for a TreeMap is red and black tree and all the complexity is abstracted by the NavigableMap interface thereby making it quite simple to use.