「Kotlin」isEmptyメソッドでmapが空であるかを判定する

環境
Windows11 pro 64bit
Java 17.0.2
kotlin 1.6.10

書式
map名.isEmpty()
isEmpty関数を使って、mutamutableMapでmapが空であるかを判定します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fun main() {
val cftA = mutableMapOf('s' to 22, 't' to 33)
val cftB: Map<Char, Int> = mutableMapOf()
val cftC: Map<Char?, Int?> = mutableMapOf(null to null)
println( cftA.isEmpty() )
println( cftB.isEmpty() )
println( cftC.isEmpty() )
}
fun main() { val cftA = mutableMapOf('s' to 22, 't' to 33) val cftB: Map<Char, Int> = mutableMapOf() val cftC: Map<Char?, Int?> = mutableMapOf(null to null) println( cftA.isEmpty() ) println( cftB.isEmpty() ) println( cftC.isEmpty() ) }
fun main() { 
     val cftA = mutableMapOf('s' to 22, 't' to 33)
    val cftB: Map<Char, Int>  = mutableMapOf()
    val cftC: Map<Char?, Int?>  = mutableMapOf(null to null)
    
    println( cftA.isEmpty() ) 
    println( cftB.isEmpty() ) 
    println( cftC.isEmpty() ) 
}

実行結果
false
true
false

Kotlin

Posted by arkgame