kotlin mutableSetの最初の値を取得を取得するサンプル

環境
Windows11 pro 64bit
java 19.0.1
kotlin 1.7.20-release-201

構文
mutableSet名.first()
mutableSetの最初の値を取得するには、「first」を利用します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fun main() {
val s = mutableSetOf( "tokyo", "study", "toto", "wai", "ccc" )
println( s )
println( s.first() )
}
fun main() { val s = mutableSetOf( "tokyo", "study", "toto", "wai", "ccc" ) println( s ) println( s.first() ) }
fun main() {

    val s = mutableSetOf( "tokyo", "study", "toto", "wai", "ccc" )

    println( s ) 

    println( s.first() ) 
    
}

実行結果
[tokyo, study, toto, wai, ccc]
tokyo

Kotlin

Posted by arkgame