Array
In this page:
Array
A Scala Array is a fixed-size, mutable sequence backed directly by the JVM's native array type, offering fast indexed access. Unlike List, individual elements of an Array can be reassigned after creation, though its length is fixed. Arrays are typically used when you need Java interop or maximum performance for indexed access.
Note: Array elements can be mutated in place with arr(i) = newValue, unlike the elements of an immutable List.
Example: Array
object Main extends App {
val numbers = Array(10, 20, 30, 40)
println(numbers.length)
println(numbers(0))
numbers(1) = 99
println(numbers.mkString(", "))
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: