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

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

書式
mutableSet名.first()
first()を使用してmutableSetの最初の値を取得します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
fun main() {
val str = mutableSetOf( "study", "skill", "become", "smart" )
println( str )
println( str.first() )
}
fun main() { val str = mutableSetOf( "study", "skill", "become", "smart" ) println( str ) println( str.first() ) }
fun main() {
   
    val str = mutableSetOf( "study", "skill", "become", "smart" )

    println( str )

    println( str.first() ) 
}

実行結果
[study, skill, become, smart]
study

Kotlin

Posted by arkgame