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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Since
java.util.Mapis 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 aString[].Just do:
String str2 = map.get("foo")and always check ifstr2 != nullbefore 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
Stringkey to aCollectionofStrings. It’s easy and it works. Choose the rightCollectiondepending on how much frequently it is changed, if you need it sorted, etc… Often aLinkedListis fairly good.