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




FIRST() - FUNCTION


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.


Example :



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


Output :



  The first element in the Set is : 5

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 first() method is used to get the first element in the Set.


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