List
is in-efficient SC-P1007Scala's List
data-structure is an immutable sequence of elements, implemented as a linked list. Therefore, operations such as append
have a complexity of O(n). Repeatedly calling such methods can impact the performance of your application. If you need to append a large number of elements, it is suggested that you use a different structure such as an ArrayBuffer
or a Vector
depending on whichever that suites your needs.
List(1, 2, 3) :+ 4
val arrayBuffer = ArrayBuffer[Int](1, 2, 3)
arrayBuffer += 4