Start learning free

LESSON 93 OF 348 · ARRAYS I

Arrays in Scala in Scala

Lesson

The entries of an ArrayBuffer are mutable and can be changed freely, using indices and index assignment:

Index assignment takes an index and a value and changes the element placed at that index with the argument value:

val numbers = scala.collection.mutable.ArrayBuffer(50, 40, 30)

numbers(0) = 15
numbers(2) = -1

// numbers is now [15, 40, -1]

Assignment
Follow the Coding Tutorial and let's play with some arrays.


Hint
Look at the examples above if you get stuck.


STEP 1 OF 2
    Ctrl + Enter to check

    Updating Elements in Scala

    Keep going with ScalaAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free