どうも、ちょげ(@chogetarou)です。
Mapの全てのキーを取得する方法を紹介します。
方法

Mapの全てのキーを取得するには、keysプロパティを使います。
具体的には、map.keys
のように、Mapのkeysプロパティにアクセスします。
val result = map.keys
上記のkeysプロパティは、アクセス元のMapの全てのキーを取得します。
使用例
fun main() {
val numbers = mapOf(
"one" to 1,
"two" to 2,
"three" to 3,
"four" to 4,
"five" to 5
)
val keys = numbers.keys
println(keys)
}
出力:
[one, two, three, four, five]
コメント