Scala

You are currently auditing this course.
40 / 53

Scala - Assessment - Declare an array

An array is one of the collections in Scala, which stores a fixed-size sequential collection of elements of the same type.

We will declare an array of strings, named strArray, having below elements in the same order.

Elements of the array:
John
Doe
Jane
Sach

In general, providing the datatype of the variable is optional. So, an array can be defined in either of the below ways:

var ar:Array[String] = Array(.....)

var ar = Array(.....)

But, the first statement specifies that the array will consist of strings only, so :Array[String] is required here.

INSTRUCTIONS
  • Switch to the Jupyter tab.

  • Declare the array of the required name and having required items in the Jupyter.

  • Press Shift+Enter. You should see the output showing the array name and its content.

  • Click on "Submit Answer".


Loading comments...