Are Kotlin `MutableList`s implemented like a linke...
# getting-started
c
Are Kotlin `MutableList`s implemented like a linked list under the hood? Can I pop/append from both ends or from the middle cheaply? Or is this an expensive calculation
d
MutableList
is an interface without implementation.
Usually the implementation is an
ArrayList
but that is up to you.
You might want to look at the new
ArrayDeque
.
c
You mean I can specify an implementation when I write
mutableListOf()
?
d
Haha nope. That is an
ArrayList
. What I meant is that you can have multiple implementations of
MutableList
.
c
Oh I see
I didn't realize that
MutableList
was an interface, but it was in the docs staring at me the whole time lol
Not trying to disprove you, but I can't find docs that indicate it would be an
ArrayList
though
Is this something you just kinda have to know about the language?
d
Yes, it's not guaranteed to be an
ArrayList
I guess, but looking at the source code.... we know it is 🙂.
c
Got it! Thank you very much
d
If you absolutely want an array list, use
arrayListOf