scalaappendarraybufferscala-2.13

What's the difference between ArrayBuffer.addOne and ArrayBuffer.append?


2.13.3 API says:

def addOne(elem: A): ArrayBuffer.this.type

Adds a single element to this array buffer.

final def append(elem: A): ArrayBuffer.this.type

Appends the given elements to this buffer.

They seem to do the exact same thing?


Solution

  • They are the same thing. ArrayBuffer is a descendent of Buffer, which defines append:

    @`inline` final def append(elem: A): this.type = addOne(elem)
    

    addOne is implemented in ArrayBuffer as part of its implementation towards Growable.

    See: Buffer.scala.