Reputation: 3375
Hi i have a Map<Str1,Str2>
and i need to get the array of str2 where
str1=="foo"
how can i do that?
thanks
Upvotes: 1
Views: 438
Reputation: 11403
Since java.util.Map
is not a multi-map, then the entry having "foo" as a key, if it exists, it's unique. So I don't see why you should get a String[]
.
Just do: String str2 = map.get("foo")
and always check if str2 != null
before referring to it later.
If you are interested in a multi-map (many entries for a key), then search Apache Commons Collections for it, or you can implement a multi-map yourself very easily, mapping any String
key to a Collection
of String
s. It's easy and it works. Choose the right Collection
depending on how much frequently it is changed, if you need it sorted, etc... Often a LinkedList
is fairly good.
Upvotes: 3