Using
collections
Iterating over a collection:
for
(item in items)
{
println(item)
}
Checking if a collection contains an
object using in operator:
when
{
"orange" in items ->
println("juicy")
"apple" in items ->
println("apple is fine too")
}
Using lambda expressions to filter
and map collections:
fruits
.filter
{ it.startsWith("a") }
.sortedBy
{ it }
.map
{ it.toUpperCase() }
.forEach
{ println(it) }
Creating
basic classes and their instances:
val
rectangle = Rectangle(5.0, 2.0) //no 'new' keyword required
val
triangle = Triangle(3.0, 4.0, 5.0)
Hello Reader
You can comment if any confusion in syntax or if need more explanation we'll reply you ASAP.
Thank you Safe & Happy Coding. :)