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




MUTABLESETOF() - FUNCTION


Using the mutableSetOf() method, we can create a mutable set(i.e. The Set values can be changed/replaced).


Example :



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


Output :



  [5, 'John', 'Kotlin']

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


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


var x = mutableSetOf(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.