E&ICT IIT Roorkee - Data Engineering Course at Rs. 1,999 (90% OFF) | Expires in

 Enroll Now

Scala

40 / 52
   

Scala - Assessment - Declare a List of strings

A list is another collection available in Scala.

A list is similar to an array but lists are immutable which means that the elements of a list cannot be changed by assignment and the lists represent a linked list whereas the arrays are flat.

for example, the list of days in week:

// Make a list via the companion object factory
val days = List("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")

Here is an example of a list of numbers:

val mainList = List(3, 2, 1)
INSTRUCTIONS

Declare the list in Jupyter named strList, having these elements in the same order:

  • apple
  • banana
  • mango
  • orange
  • pears

Here, we must define the variable as a list of Strings as is the requirement above.

Note that the list is displayed with its contents. Once you have run the scala code using SHIFT+ENTER, please click on "Submit Answer".