我需要将值存储在 map 中,如下所示:
val map = HashMap<String, Set<String>>()
But it is hard to interact with Set inside the map.
Kotlin中是否有类似于 Multimap in Google Guava的多 map 实现?
我需要将值存储在 map 中,如下所示:
val map = HashMap<String, Set<String>>()
But it is hard to interact with Set inside the map.
Kotlin中是否有类似于 Multimap in Google Guava的多 map 实现?
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
备选方案:
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)
或者别的什么.