A Scala list is a collection of data stored as a linked list. In Scala, a list is immutable, meaning it cannot be changed. To remedy this, Scala offers List-Buffer. There are multiple ways to update a list and add new elements such as using the ":+" method: It adds new elements at the end of a list.
Syntax:
list_Name :+ element_Name
Example:
object Colours
{
def main(args: Array[String])
{
val myList = List ("Red" , "White")
println("List’s Content : " + myList)
println(" Appending/adding elements at the end of list!")
val updatedList = myList :+ "Blue"
println("Updated List’s Content: " + updatedList)
}
}
Output:
List’s Content : List(Red, White)
Appending/adding elements at the end of the list!
Updated List’s Content : List (Red, White, Blue)