Kotlin map Collection
The map is an interface and a collection in Kotlin. Maps are used to hold the pairs of objects in the form of key/value.
The map is an interface and a collection in Kotlin. Maps are used to hold the pairs of objects in the form of key/value.
In Kotlin, you may define and use the lambda and anonymous function, that is called “function literals”.
A list is a generic collection of elements. Kotlin has three Collections while List is one of those. The other two collections are Set and Map.
The Kotlin code below simply displays the “Hello World” on the screen and this is followed by explaining code lines in that program:
In Kotlin, the while works just like in Java. So, if your background is Java then you already know how it works. For beginners, the while loops execute a block of code until the given condition is True.
The array class represents an array in Kotlin. Array class has get and set functions. The items in array are called elements.
Kotlin if is an expression that returns a value. This is different if compared with the other languages where if acts as a statement. As, it acts as an expression in Kotlin, so there is no ternary operators (condition ? then : else).
In Kotlin, we have no switch statement. Instead, Kotlin replaces the switch with the When expression.
In Kotlin, the ranges has the operator form .. (double dot). A Kotlin range can also be created by using the rangeTo() and downTo() function.
The for loop in Kotlin can be used to iterate through anything that provides an iterator. For example, a range, array, string, etc.