I am adding an element into a MutableList and I want to know its index.
mutableList.add(foo)
Will the index of the most recently added element always be the last index mutableList.size - 1
like it is with ArrayList
?
I don't want to use mutableList.indexOf(foo)
because I believe it takes O(n). I'm not finding lot of documentation on these.
Yes, MutableList.add()
always adds to the end of the list (this is a requirement for any class implementing the interface). I've filed an issue to say this explicitly in the documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With