The following structure is repeated in my code: ``...
# announcements
o
The following structure is repeated in my code:
Copy code
val arrayList : ArrayList<String> = arrayListOf()
for(person in 0..listOfPersonsIndex){
arrayList.add(person[i])
}
I would like to no do that declaration of empty arraylist and the assign it. Is there a cleaner way to immediately assign a value for it in the stdlib?
o
Is listOfPersonsIndex a List? If so,
listOfPersonsIndex.toList()
would be all you need.
☝️ 1
z
also
List(n) { person[it] }
or best of all, just
person.toMutableList()