kotlin minusメソッドとlistOfメソッドでmutableMap複数のkeyを削除するサンプル

環境
Ubuntu 22.04.1 LTS
openjdk 11.0.16 2022-07-19
Kotlin version 1.7.20-release-201

構文
minus(listOf(キー1,キー2′))
minusメソッドとlistofメソッドを使って、mutableMapで指定した複数のkeyを削除します。
Listを使用して、複数のkeyを削除します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fun main() {
val kk = mutableMapOf('x' to 36, 'y' to 17, 'z' to 23, 's' to 44)
println( kk.minus(listOf('z','s')) )
println( kk )
}
fun main() { val kk = mutableMapOf('x' to 36, 'y' to 17, 'z' to 23, 's' to 44) println( kk.minus(listOf('z','s')) ) println( kk ) }
fun main() {

    val kk = mutableMapOf('x' to 36, 'y' to 17, 'z' to 23, 's' to 44)    
        
    println( kk.minus(listOf('z','s')) )
    println( kk ) 

}

実行結果
{x=36, y=17}
{x=36, y=17, z=23, s=44}

Kotlin

Posted by arkgame