1. Array
2, ArrayBuffer
3. Traversing array and Arraybuffer
4. Common Array Operations
1. Array
In Scala, array stands for a similar meaning to Java and is an immutable array of lengths. Since both Scala and Java are running in the JVM, the two sides can call each other, and the underlying implementation of the Scala array is actually a Java array.
2, ArrayBuffer
In Scala, if you need a variable-length collection class, you can use Arraybuffer. You need to import scala.collection.mutable.ArrayBuffer before use.
Create an empty arraybuffer:val B=arraybuffer[int] ()
Add an element using + = B+=1 b+= (2,3,4,5)
Add all elements from another collection B++=array (6,7,8)
Truncates the specified number of elements from the tail b.trimend (5)
Specify position Insert element B.insert (0,9,10)
Removes the element b.remove (1,3) from the specified position
Array and Arraybuffer convert each other B.toarray A.tobuffer
3. Traversing array and Arraybuffer
Using for loops and until traversal
Jump traversal
Trailing traverse
Using the enhanced for loop traversal
4. Common Array Operations
Array element summation A.sum
Get maximum value A.max
Sort an array scala.util.Sorting.quickSort (a)
Gets the contents of all elements in the array a.mkstring a.mkstring (",") a.mkstring ("(", ",", ")")
toString function a.tostring
4. Scala array