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




SETOF() - FUNCTION


Using the setOf() method, we can create an immutable set(i.e. A read only Set).


Example :



fun main() {
    var x = setOf(5, "John", "Kotlin")
    println(x)
}


Output :



  [5, John, Kotlin]

So, in the above code we have created a Set using the setOf() method.


And put an Integer type value (i.e. 5) and two String type value (i.e. John and Kotlin)


var x = setOf(5, "John", "Kotlin")

And initialised to the variable x.

java_Collections

So, we can see that two different data types are assigned to a Set.


In the next line we have printed the Set using the print statement.


println(x)

Now, if we see the output,

Output :



  [5, 'John', 'Kotlin']

The values are enclosed inside square brackets []. This means that the values are inside a Set.