What is the easiest way to get key associated with the max value in a map?
I believe that Collections.max(someMap) will return the max Key, when you want the key that corresponds to the max value.
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.
Basically you’d need to iterate over the map’s entry set, remembering both the "currently known maximum" and the key associated with it. (Or just the entry containing both, of course.)
For example: