I want to do something like this:
1 -> imran
2 -> ajmal
3 -> habib
4 -> saurab
4 -> tendulkar
If I use get(1)
I get
imran
Now if I use get(4)
I should get
saurab
tendulkar
Is this possible to do?
I want to do something like this:
1 -> imran
2 -> ajmal
3 -> habib
4 -> saurab
4 -> tendulkar
If I use get(1)
I get
imran
Now if I use get(4)
I should get
saurab
tendulkar
Is this possible to do?
So fir any one key, you want to return more than one or more objects in the result. One of more objects implies a List.
So you could have :
Map<Integer, List<String>> myMap = new HashMap<>();
void add(Integer key, String value) {
List<String> list = myMap.get(key);
If (list==null) {
list = new ArrayList<>();
myMap.put(key, list);
}
list.add(value);
}