Array in Scala

In Scala arrays are immutable objects.

var myArray : Array[Int] = new Array[Int](10);

/*
To create an Array with String data type, replace
Int with String
*/

First you declare variable var myArray to be of type Array[Int]. That is a Int array. If you had needed an array of e.g. String, replace String with String.

Array is 0 base indexing, meaning index starts from 0

Once created, length of an array can not be changed.

Last updated