What is the function of Array class in Scala language
This article will explain in detail what the role of Array class in Scala language is, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.
Array class
The generic array class is defined as follows.
Final class Array [A] (len: Int) extends Seq [A] {
Def length: Int = len
Def apply (I: Int): a =.
Def update (I: Int, x: a): Unit =.
Def elements: Iterator [A] =.
Def subArray (from: Int, end: Int): Array [A] =.
Def filter (p: a = > Boolean): Array [A] =.
Def map [B] (f: a = > B): Array [B] =.
Def flatMap [B] (f: a = > Array [B]): Array [B] =.
}
If T is not a type parameter or abstract type, the type Array [T] represents the native array type [] T in the host system. In this case length returns the length of the array, apply represents the subscript, and update indicates the element update. Due to the existence of syntax sugars for apply and update operations (§6.25), the following are the corresponding array xs operations in Scala and Java/C#:
Scala Java/C#
Xs.length xs.length
Xs (I) xs [I]
Xs (I) = e xs [I] = e
Standard reference class
The array also implements the sequence feature scala.Seq and defines the elements method to return an Iterator that contains all the elements in the array.
Because the implementation of an array of parameterized types in Scala is different from that of an array in the host language, you need to pay attention to some minor differences when dealing with arrays. The explanation is as follows.
First of all, unlike arrays in Java or C #, arrays in Scala are not covariant; that is, in Scala, S