

All the methods in this interface support read-only access to the list. And, List in Kotlin is an interface that extends the Collection interface. List in Kotlin A list is a generic ordered collection of elements that can contain duplicate values. If we are interested in working with indices, we can use indices property of array. Overview In this tutorial, we’ll discuss working with lists in Kotlin. You can convert a range (or any Iterable) to a List with toList (): You can use IntRange in listOf, but you will get a list of IntRanges.
Sunday Monday Tuesday Wednesday Kotlin for loop Example with Integer array That syntax creates a list of ranges ( ListVar days = arrayOf("Sunday","Monday","Tuesday","Wednesday")

Kotlin’s for loop syntax is similar to for each syntax in Java.

The good news is that Kotlin can help us avoid this kind of error because it's a null safe language. These happen whenever you try to call a method or read a property of an object reference which is null. We can iterate over an array, collection, string, range, or anything which can be iterated with the help of a for loop.In this article, we will see different ways to iterate through collections in kotlin using for loop, for with indices, for loop with range and until. Nullability If you're an Android coder, you must have come across the infamous NullPointerException errors in your app. The for loop is used to iterate over any Kotlin object which can be iterated. The for loop in Kotlin is similar to forEach loop in Java. There is no traditional for loop in Kotlin unlike C, C++, Java etc., which will execute until a condition returns false. In this tutorial, we will discuss about for loop in Kotlin. Using forEachIndexed () method Using a ListIterator and a while loop Here is a complete source code to demonstrate five ways of looping over a list in Kotlin.
