Lockdown Offer: FLAT 75% + Addl. 25% Off + 30-days Extra Lab on ALL Courses | Use Coupon Code LD25 during Checkout | Offer Expires InEnroll 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? Check this discussion
Taking you to the next exercise in seconds...