The mangle method is returning a new map which switch the key with value. In other words, it converts (
String => Integer) mapping into (Integer => String).
The m2 map is something like:
1 => "a"
2 => "b"
That's why m2.get("a") returns null (there is no such key in the map) and m2.get(2) returns "b" as it's the actual value for this key.
The generic code would look like this:
and the result remains unchanged.