kotlin mutableMapをIterableに変換する

kotlin mutableMapをIterableに変換する

kotlinで、mutableMapをIterableに変換する手順を記述してます。対象のmapに「asIterable」を指定します。

環境

  • OS windows11 home
  • java 19.0.1
  • kotlin 1.7.20-release-201

手順

mutableMapをIterableに変換するには、「asIterable」で可能です。

map名.asIterable()

実際に、変換してみます。

fun main() {

    val m = mutableMapOf('a' to 1, 'b' to 2, 'c' to 3)

    var t = m.asIterable()

    println( t is Set ) // true
    println( t is Map<*,*> ) // false

}

変化されていることが確認できます。戻り値は「Set」になります。