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 { it.name() /* assumes name() function exists */ }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)