I have a situation where I need to have a key-value pair data structure. But it should allow multiple keys and values corresponding to that.
It would be like :
a - 1
b - 2
a - 3
So, when retrieving, I can have getFirstValueOfKey(key)
and get 1...something like that.
Is there something existing or I need to implement this?
If I need to implement this, I am thinking to proceed as :
Create a class, which a=can hold K-V pairs, and add them to a list. And write corresponding API's required. Is this right approach? Shall I continue like this?
EDIT : I actually want multiple entries of keys in the data structure.
EDIT : The thing is, I want to maintain order in which new entries(keys) were made, i.e. I want to have sequence of keys how they are put, (a and then b and then a). If array of values is used, this sequence is lost.
Example :
a -> 1 (Time 0) b -> 2 (Time 1) a -> 3 (Time 2)
These time stamps are also required.