简体   繁体   中英

How to devine multiple variables in 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];
}

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM