Mateus Gondim Mateus Gondim - 1 year ago 100
Android Question

Kotlin - Most idiomatic way to convert a List to a MutableList

I have a method(

) that returns a List and I need to convert this result to a MutableList. Currently the best way I can think of doing it is like this:

val contacts: MutableList<Contact> = ArrayList(presenter.getContacts())

Is there a more idiomatic/"less Java" way to do that?

Answer Source

Consider using the toMutableList() function:


It is defined as an extension for Collection<T>.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download