Arrays in Kotlin | Kotlin Functional Programming

 package com.example.my_kotlin_practice


fun main(args: Array<String>) {
val array1 = arrayOf<Int>(10,1,20,30,40,50)
println(array1.joinToString())

val array2 = arrayOf<String>("CS","IT","Chemistry","Physics")
// println(array2.contentToString())
for(i in array2) {
println(i)
}
for((i,e) in array2.withIndex()) {
println("$i : $e")
}
array2[
2] = "Maths"
array2.set(3,"Biology")
println("array2[2] : ${array2[2]}")
println(array2.get(3))
}

OUTPUT :

10, 1, 20, 30, 40, 50 CS IT Chemistry Physics 0 : CS 1 : IT 2 : Chemistry 3 : Physics array2[2] : Maths Biology Process finished with exit code 0

Comments

Popular posts from this blog

Maps (Collections) in kotlin

Functions in Kotlin

Arrays in Kotlin