scala.collection.mutable

class ArrayBuffer

[source: scala/collection/mutable/ArrayBuffer.scala]

@serializable

class ArrayBuffer[A]
extends Mutable[A] with Buffer[A] with ResizableArray[A]
An implementation of the Buffer class using an array to represent the assembled sequence internally. Append, update and random access take constant time (amortized time). Prepends and removes are linear in the buffer size.
Author
Matthias Zenger
Version
1.0, 15/03/2004
Direct Known Subclasses:
Script, NodeBuffer

Values and Variables inherited from ResizableArray
array
Method Summary
override def ++ [B >: A](that : Iterable[B]) : ArrayBuffer[B]
Appends two iterable objects.
override def ++: (iter : Iterable[A]) : Buffer[A]
Prepends a number of elements provided by an iterable object via its elements method. The identity of the buffer is returned.
override def ++= (iter : Iterable[A]) : Unit
Appends a number of elements provided by an iterable object via its elements method. The identity of the buffer is returned.
override def ++= (src : Array[A], start : Int, len : Int) : Unit
Appends a number of elements in an array
def +: (elem : A) : Buffer[A]
Prepends a single element to this buffer and return the identity of the buffer. It takes time linear in the buffer size.
def += (elem : A) : Unit
Appends a single element to this buffer and returns the identity of the buffer. It takes constant time.
override def apply (i : Int) : A
Returns the i-th element of this ArrayBuffer. It takes constant time.
def clear : Unit
Clears the buffer contents.
override def clone : Buffer[A]
Return a clone of this buffer.
override def equals (obj : Any) : Boolean
Checks if two buffers are structurally identical.
def insertAll (n : Int, iter : Iterable[A]) : Unit
Inserts new elements at the index n. Opposed to method update, this method will not replace an element with a one. Instead, it will insert a new element at index n.
def remove (n : Int) : A
Removes the element on a given index position. It takes time linear in the buffer size.
protected override def stringPrefix : java.lang.String
Defines the prefix of the string representation.
def update (n : Int, newelem : A) : Unit
Replace element at index n with the new element newelem. It takes constant time.
Methods inherited from ResizableArray
initialSize, size0, size0_=, length, reduceToSize, copyToArray, copyToBuffer, elements, ensureSize, swap, copy
Methods inherited from Buffer
+, ++=, ++, ++, -=, append, appendAll, prepend, prependAll, insert, trimStart, trimEnd, <<, hashCode
Methods inherited from Mutable
projection, readOnly, drop, take, slice, reverse
Methods inherited from RandomAccessSeq
partition, patch, toStream, safeIs
Methods inherited from Seq
lengthCompare, size, isEmpty, concat, last, lastOption, first, firstOption, headOption, isDefinedAt, lastIndexOf, findIndexOf, indexOf, map, flatMap, filter, slice, takeWhile, dropWhile, contains, subseq, toArray, toSeq, equalsWith, startsWith, startsWith, endsWith, indexOf, containsSlice
Methods inherited from Collection
toString
Methods inherited from Iterable
foreach, forall, exists, find, foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, sameElements, toList, mkString, mkString, mkString, addString, addString, addString, hasDefiniteSize
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from AnyRef
getClass, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Method Details
def +=(elem : A) : Unit
Appends a single element to this buffer and returns the identity of the buffer. It takes constant time.
Parameters
elem - the element to append.
Overrides
Buffer.+=

override def ++=(iter : Iterable[A]) : Unit
Appends a number of elements provided by an iterable object via its elements method. The identity of the buffer is returned.
Parameters
iter - the iterable object.
Returns
the updated buffer.
Overrides
Buffer.++=

override def ++[B >: A](that : Iterable[B]) : ArrayBuffer[B]
Appends two iterable objects.
Overrides
Buffer.++

override def ++=(src : Array[A], start : Int, len : Int) : Unit
Appends a number of elements in an array
Parameters
src - the array
start - the first element to append
len - the number of elements to append
Overrides
Buffer.++=

def +:(elem : A) : Buffer[A]
Prepends a single element to this buffer and return the identity of the buffer. It takes time linear in the buffer size.
Parameters
elem - the element to append.
Returns
the updated buffer.
Overrides
Buffer.+:

override def apply(i : Int) : A
Returns the i-th element of this ArrayBuffer. It takes constant time.
Parameters
i - the specified index.
Returns
the i-th element.
Throws
Predef.IndexOutOfBoundException - if i is out of bounds.
Overrides
ResizableArray.apply

override def ++:(iter : Iterable[A]) : Buffer[A]
Prepends a number of elements provided by an iterable object via its elements method. The identity of the buffer is returned.
Parameters
iter - the iterable object.
Returns
the updated buffer.
Overrides
Buffer.++:

def insertAll(n : Int, iter : Iterable[A]) : Unit
Inserts new elements at the index n. Opposed to method update, this method will not replace an element with a one. Instead, it will insert a new element at index n.
Parameters
n - the index where a new element will be inserted.
iter - the iterable object providing all elements to insert.
Throws
Predef.IndexOutOfBoundsException - if n is out of bounds.
Overrides
Buffer.insertAll

def update(n : Int, newelem : A) : Unit
Replace element at index n with the new element newelem. It takes constant time.
Parameters
n - the index of the element to replace.
newelem - the new element.
Throws
Predef.IndexOutOfBoundsException - if n is out of bounds.
Overrides
Mutable.update, Buffer.update

def remove(n : Int) : A
Removes the element on a given index position. It takes time linear in the buffer size.
Parameters
n - the index which refers to the element to delete.
Returns
the updated array buffer.
Throws
Predef.IndexOutOfBoundsException - if n is out of bounds.
Overrides
Buffer.remove

def clear : Unit
Clears the buffer contents.
Overrides
Buffer.clear

override def clone : Buffer[A]
Return a clone of this buffer.
Returns
an ArrayBuffer with the same elements.
Overrides
Buffer.clone

override def equals(obj : Any) : Boolean
Checks if two buffers are structurally identical.
Returns
true, iff both buffers contain the same sequence of elements.

protected override def stringPrefix : java.lang.String
Defines the prefix of the string representation.
Overrides
Buffer.stringPrefix