A Multimap is a map that allows mapping of a single key to multiple values. Kotlin does not provide any standard implementation of the Multimap class, but we can implement our own Multimap class in Kotlin.

Following is a simple implementation of the Multimap class in Kotlin using the HashMap and Collection class.

Download Code

 
Output:

—– Printing Multimap with keySet() function —–

George: [Washington, Bush]
Zachary: [Taylor]
John: [Adams, Tyler, Kennedy]

That’s all about implementing a Multimap in Kotlin.