← Back to Scala Course | Chapter 6: Collections Basics | Lesson 3 of 8

Array

In this page:

  1. Array

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

markup
object Main extends App {
  val numbers = Array(10, 20, 30, 40)

  println(numbers.length)
  println(numbers(0))

  numbers(1) = 99
  println(numbers.mkString(", "))
}
🔒

Chapter Quiz — Complete all 8 topics to unlock

0/8 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.