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.
Vector
. IndSeq
from scalaz should be even better.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.