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




LIST - listOf()


Using the 'listOf()' method, we can create an immutable list(i.e. A read only List).


Example :



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


Output :



 [5, 'John', 'Kotlin']

So, in the above code we have created a 'List' using the 'listOf()' method.


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


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

And initialised to the variable 'x'.


java_Collections

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


In the next line we have printed the 'List' using the print statement.


println(x)

Now, if we see the output,


Output :



 [5, 'John', 'Kotlin']