get() is used to access any element in the List using its index.
We have the 'List' with three values, 5, 'John' and 'Kotlin'. And we want to access the second element i.e. 'John'.
fun main() { var x = listOf(5, "John", "Kotlin") println(x.get(1)) }
So, in the above code we have created a 'List' and initialised to the variable 'x'.
Now, let us see, how the values are positioned in the List,
So, as we can see the elements are positioned as '0', '1' and '2'. And if we want to access the second element, we can refer to the position '1' using the 'get()' method (i.e. 'x.get(1)').
And the print statement prints the value of the second element of the 'List' (i.e. 'John').