Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Array and WrappedArray in Scala

Tags:

arrays

scala

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!

like image 470
Guillaume Avatar asked Jan 26 '17 20:01

Guillaume


People also ask

What is WrappedArray in Scala?

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.

What is difference between array and list in Scala?

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.

What is array in Scala?

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.

What is the difference between SEQ and list in Scala?

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.


1 Answers

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.

like image 168
puhlen Avatar answered Sep 20 '22 12:09

puhlen