logo CodeStepByStep logo

leastCommon

Language/Type: Java Map collections
Related Links:

Write a method leastCommon that accepts a HashMap whose keys are strings and whose values are integers as a parameter and returns the integer value that occurs the fewest times in the map. For example, if a map named m contains {Alyssa=22, Char=25, Dan=25, Jeff=20, Kasey=20, Kim=20, Mogran=25, Ryan=25, Stef=22}, the call of leastCommon(m) returns 22. If there is a tie, return the smaller integer value. If the map is empty, throw an IllegalArgumentException.

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.