我需要将值存储在 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)

或者别的什么.

Kotlin相关问答推荐

在没有外部 map 的情况下转换列表项

如何在 Big Data 中使用Inc过滤器?

如果启用了Flyway迁移,则不能具有配置属性';datources.default.架构-生成

新的jOOQ Gradle插件无法正确处理自引用关系

可选的.在kotlin中不使用泛型参数

为什么不';Kotlin是否在数据类构造函数中隐式分配null值可为null的字段?

在Kotlin中的嵌套when语句中,else块是强制性的吗?

如何更改默认推断没有接收者的函数类型?

如何在 Spring Boot 3 中为内部类提供运行时提示

每个 Kotlin 版本的默认 Kotlin 语言版本是什么?

kotest 更改环境变量

Kotlin 中二叉树的深度

Mixin 在 Jackson 中添加 defaultImpl 不起作用

为什么我们在 kotlin 中需要 noinline?

为什么 IntelliJ Idea 无法识别我的 Spek 测试?

如何禁用智能投射突出显示 Kotlin?

TextField maxLength - Android Jetpack Compose

ObjectAnimator.ofFloat 不能直接在kotlin中取Int作为参数

使用导航组件在BottomNavigationView中传递参数

Android Jetpack Compose 中的文本渐变