Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   RUBY   
   C++   




LAST() - FUNCTION


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.


Example :



fun main() {
    var x = setOf(5, "John", "Kotlin")
    println("The last element in the Set is : "+x.last())
}


Output :



  The last element in the Set is : Kotlin

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,

java_Collections

The last() method is used to get the first element in the Set.


println("The last element in the Set is : "+x.last())