Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there Multimap in Kotlin?

Tags:

kotlin

I need to store values in map likie this:

 val map = HashMap<String, Set<String>>() 

But it is hard to interact with Set inside the map.

Is there any multimap implementations in Kotlin like Multimap in Google Guava?

like image 469
Arseniy Avatar asked Dec 16 '17 15:12

Arseniy


People also ask

How do I map a list to another list in Kotlin?

You can use the map() function to easily convert a list of one type to a list of another type. It returns a list containing the results of applying the specified transform function to each element in the original list. That's all about conversion between lists of different types in Kotlin.


1 Answers

No, there currently isn't. And there probably won't be one in the future.

Reference: https://discuss.kotlinlang.org/t/the-standard-library-and-a-kotlin-manifesto/1303/6

Alternative:

org.springframework.util.MultiValueMap org.apache.commons.collections4.MultiMap com.google.common.collect.Multimap 

To play with the Set in your example, you can:

map["key"].forEach(::println) 

Or something else.

like image 57
ice1000 Avatar answered Sep 18 '22 17:09

ice1000