Scala lists are immutable by default. You cannot “add” an item, but you can create a new list by adding a new item in front. Since this is a new list, you need to reassign the link (so you cannot use val).
var dm = List[String]() var dk = List[Map[String,AnyRef]]() ..... dm = "text" :: dm dk = Map(1 -> "ok") :: dk
The :: operator creates a new list. You can also use shorter syntax:
dm ::= "text" dk ::= Map(1 -> "ok")
NB: In scala, do not use the Object type, but Any , AnyRef or AnyVal .
paradigmatic Jul 02 2018-11-11T00: 00Z
source share