Is there a method (maybe with Google Collections) to obtain the min value of a Map(Key, Double)?
In the traditional way, I would have to sort the map according to the values, and take the first/last one.
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.
You can use the standard
Collections#min()for this.Update: since you need the key as well, well, I don’t see ways in
Collectionsor GoogleCollections2API since aMapis not aCollection. TheMaps#filterEntries()is also not really useful, since you only know the actual result at end of iteration.Most straightforward solution would then be this:
(nullcheck on
minleft aside)