Scala

Scala

Made by DeepSource

Appending to List is in-efficient SC-P1007

Performance
Major

Scala'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.

Bad practice

List(1, 2, 3) :+ 4

Recommended

val arrayBuffer = ArrayBuffer[Int](1, 2, 3)
arrayBuffer += 4