23 Lists

  • List are constructed simply using List(element1, element2, ...)
  • List elements can be of any type, but the List final type will be the lowest common denominator

    class Foo(val value1:Int)
    class Bar(value1:Int, val value2:Int) extends Foo(value1)
    val list:List[Foo] = List(new Foo(1), new Bar(2,3))
    
  • The default List in scala, is scala.List which points to scala.collection.immutable.List src docs, and defined in scala/package.scala src docs
  • The default List is implemented as a Linked list
  • It is immutable (any “changes” craete a new list, the original is untouched)

See Also opens in new page

Code editor is using Scalakata.com written by Guillaume Massé