Kotlinlearncs.online LogoJava
Return to List

Homework: Invert a Map

Created By: Geoffrey Challen
/ Version: 2020.10.0

Create a public class called Inverter with a single class method named invert. invert should accept a Map<String, Integer> and return a Map<Integer, String> with all of the key-value pairs swapped.

You can assert that the passed map is not null.

Because values are not necessarily unique in a map, normally you would need a way to determine what the right approach is when two keys map to the same value. However, the maps passed to your function will not have any duplicate values.

Related Lessons

Stuck? You may find these lessons helpful: