kotlin isEmptyでmutableMapでmapが空であるかを判定する

環境
Windows10 Home 64bit
Java 19.0.1
Kotlin 1.7.20-release-201

書式
val mutableMap変数名 =mutableMapOf(キー1 to 値1,キー2 to 値2,…
mutableMap変数名.isEmpty()
isEmptyを使ってmutamutableMapでmapが空であるかを判定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fun main() {
val tt = mutableMapOf('t' to 101, 'o' to 202, 'y' to 303)
val ttB: Map<Char, Int> = mutableMapOf()
println( tt.isEmpty() ) // false
println( ttB.isEmpty() )
}
fun main() { val tt = mutableMapOf('t' to 101, 'o' to 202, 'y' to 303) val ttB: Map<Char, Int> = mutableMapOf() println( tt.isEmpty() ) // false println( ttB.isEmpty() ) }
fun main() {
       val tt = mutableMapOf('t' to 101, 'o' to 202, 'y' to 303)
      val ttB: Map<Char, Int>  = mutableMapOf()
          println( tt.isEmpty() ) // false
        println( ttB.isEmpty() ) 
}

実行結果
false
true

Kotlin

Posted by arkgame