October 2018
Intermediate to advanced
370 pages
9h 15m
English
In this section, will discuss immutable lists and their interfaces. Before going into details, however, let's have a quick look at list declaration. Kotlin provides different ways to define a list, the simplest one being the listOf keyword with comma-separated values:
val listOfInteger = listOf(1,2,3,4,5,6)val listOfDouble = listOf(1.0,2.0,3.0,4.0,5.0,6.0)val listOfString = listOf("One","Two","Three","Four")
The listOf keyword not only defines the list but initializes it as well. The type of the list depends on the list elements, and the size of the list depends on the number of elements that are assigned to it. We can create lists of integers and strings and display each element using a for loop:
fun listInt(){ val ...Read now
Unlock full access