「Kotlin」noneメソッドでmapの要素が空であるかを判定する

環境
Windows11 pro 64bit
Java 17.0.2
kotlin 1.6.10

書式
val map名 = mutableMapOf(要素1, 要素2,…)
map名.none()
noneメソッドを利用して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.none())
println( cftB.none())
println( cftC.none() )
}
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.none()) println( cftB.none()) println( cftC.none() ) }
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.none()) 
    println( cftB.none()) 
    println( cftC.none() ) 
}

実行結果
false
true
false

Kotlin

Posted by arkgame