We can get the size of an array using the size
property. Array size is the number of elements that an array contains. It is similar to the length
property.
array.size
The value returned is an integer value that represents the number of elements present in the array.
object Main extends App {// create some arraysval randomNumbers = Array(34, 2, 5, 70, 1)val fruits = Array("Pineapple", "Banana", "Orange")val cgpas : Array[Double] = Array(3.4, 4.5, 2.5, 0.5)// get and print there sizesprintln(randomNumbers.size)println(fruits.size)println(cgpas.size)}
size
property. We then print the values to the console.