The for loop with a collection

The for loop can also be used to loop through List and Set as well, as follows:

var letters = stringFormatter.csvToList("A,B,C,D,E,F,G,H,I");

if (letters != null) {
for (letter in letters) {
var word : String = when(letter) {
"A" -> "Apple";
"B" -> "Ball";
"C" -> "Cat";
"D" -> "Dog";
else -> "Don't Know";
}

        println("$letter for $word");
}
}

Here, the letters variable is a List of strings objects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.21.162.87