Warning: Trying to access array offset on false in /home3/indiakep/public_html/wp-content/plugins/dw-question-answer/inc/Template.php on line 8
1 Answers
The index method is used to print both value and index numbers in an array. Let’s see one example.
Code:
fun main(args : Array<String>){
var nums = listOf(1,2,3,4)
for((i,e) in nums.withIndex())
{
println(” $i : $e”)
}
}
This code prints both Index and value.
Output:
0 : 1
1 : 2
2 : 3
3 : 4
