How to add an item to a list in Kotlin?
A more idiomatic approach would be to use MutableList instead of specifically ArrayList. You can declare: val listOfVehicleNames: MutableList<String> = mutableListOf() And add to it that way. Alternatively, you may wish to prefer immutability, and declare it as: var listOfVehicleNames: List<String> = emptyList() And in your completion block, simply reassign it: listOfVehicleNames = response.body()?.message()?.orEmpty() .map … Read more