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!
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.
Following are the point of difference between lists and array in Scala: Lists are immutable whereas arrays are mutable in Scala. Lists represents a linked list whereas arrays are flat.
Array is a special kind of collection in scala. it is a fixed size data structure that stores elements of the same data type. The index of the first element of an array is zero and the last element is the total number of elements minus one. It is a collection of mutable values.
A Seq is an Iterable that has a defined order of elements. Sequences provide a method apply() for indexing, ranging from 0 up to the length of the sequence. Seq has many subclasses including Queue, Range, List, Stack, and LinkedList. A List is a Seq that is implemented as an immutable linked list.
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.
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