The first() method is used to get the first value in the Set.
Say, we have a Set with three values, 5, John and Kotlin.
And we want to access the first element element i.e. 5.
fun main() { var x = setOf(5, "John", "Kotlin") println("The first element in the Set is : "+x.first()) }
So, in the above code we have created a Set and initialised to the variable x.
var x = setOf(5, "John", "Kotlin")
Now, let us see, how the values are positioned in the Set,
The first() method is used to get the first element in the Set.
println("The first element in the Set is : "+x.first())