PG Certificate Course in Data Science, AI & Machine Learning by IIT Roorkee. Apply Now & Get up to Rs. 75,000 OFF! Offer Ends in:Apply Now
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)
Declare the list in Jupyter named
strList, having these elements in the same order:
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".
Note - Having trouble with the assessment engine? Follow the steps listed here