13
votes

I'm a bit confused in terms of those 2 collections.

I understand that Scala's Array calls Java API. In such a case, what's the role of a Wrapped Array (and its performance characteritics)?

http://www.scala-lang.org/api/current/scala/collection/mutable/WrappedArray.html

Thanks!

1

1 Answers

18
votes

WrappedArray wraps an Array to give it extra functionality. It also have a bunch of types while array extends only serializable and cloneable, This allows an array to be wrapped so it can be used in places where some generic collection type like Seq is required.

Also notable is ArrayOps Which is similar to WrappedArray in that it enriches an Array with extra operations. The difference is that Operations inArrayOps return a regular Array while operations from WrappedArray return a WrappedArray

ArrayOps has priority over WrappedArray so it will be used unless one of the types provided by WrappedArray is needed.