What would be the best Scala collection (in 2.8+), mutable or immutable, for the following scenario:
Currently I seem to be getting good performance with the mutable ArrayBuffer, but is there anything better? Is there an immutable alternative that would do as well? Thanks in advance.
Mutable: ArrayBuffer
Immutable: Vector
If you insert items at random positions more than log(N)/N of the time that you access them, then you should probably use immutable.TreeSet
as all operations are O(log(N)). If you mostly do accesses or add to the (far) end, ArrayBuffer
and Vector
work well.
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