The last() method is used to get the last value in the Set.
Say, we have a Set with three values, 5, John and Kotlin.
And we want to access the last element i.e. Kotlin.
fun main() { var x = setOf(5, "John", "Kotlin") println("The last element in the Set is : "+x.last()) }
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 last() method is used to get the first element in the Set.
println("The last element in the Set is : "+x.last())