How to devine multiple variables in Kotlin

时间:2019-01-15 18:11:52

标签: android kotlin

I want to declare multiple global variables in Kotlin with names like vehicle1, vehicle2, vehicle3... using a loop.

I think this is how one would do it in C++ ->

for(i=0; i<10; i++){
   int vehicle[1];
}

1 个答案:

答案 0 :(得分:0)

So you want an Array with 10 Strings, each one having different names right? You can do something like this:

val vehicles = emptyArray<String>()
for (i in 0 until 10) vehicles[i] = "vehicle$i"