scala.collection.mutable

class ArrayBuffer

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

@serializable

@SerialVersionUID(1529165946227428979L)

class ArrayBuffer[A](protected val override initialSize : Int)
extends Buffer[A] with GenericTraversableTemplate[A, ArrayBuffer] with BufferLike[A, ArrayBuffer[A]] with IndexedSeqLike[A, ArrayBuffer[A]] with Builder[A, ArrayBuffer[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
Martin Odersky
Version
2.8
Since
1
Direct Known Subclasses:
Script, NodeBuffer

Additional Constructor Summary
def this : ArrayBuffer[A]
Values and Variables inherited from ResizableArray
array, size0
Method Summary
override def ++= (iter : Traversable[A]) : ArrayBuffer[A]
Appends a number of elements provided by an iterable object via its iterator method. The identity of the buffer is returned.
override def ++=: (iter : Traversable[A]) : ArrayBuffer[A]
Prepends a number of elements provided by an iterable object via its iterator method. The identity of the buffer is returned.
def += (elem : A) : ArrayBuffer[A]
Appends a single element to this buffer and returns the identity of the buffer. It takes constant time.
def +=: (elem : A) : ArrayBuffer[A]
Prepends a single element to this buffer and return the identity of the buffer. It takes time linear in the buffer size.
def clear : Unit
Clear the contents of this builder
override def clone : ArrayBuffer[A]
Return a clone of this buffer.
override def companion : GenericCompanion[ArrayBuffer]
The factory companion object that builds instances of class CC
def insertAll (n : Int, seq : Traversable[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
override def remove (n : Int, count : Int) : Unit
Removes the element on a given index position. It takes time linear in the buffer size.
def result : ArrayBuffer[A]
Returns collection resulting from this builder. The buffer's contents are undefined afterwards.
override def sizeHint (len : Int) : Unit
Give a hint how many elements are expected to be added when the next `result` is called.
override def stringPrefix : java.lang.String
Defines the prefix of the string representation.
Methods inherited from ResizableArray
length, apply, update, foreach, copyToArray, reduceToSize, ensureSize, swap, copy
Methods inherited from Builder
mapResult
Methods inherited from IndexedSeqLike
thisCollection, toCollection, view, view
Methods inherited from IndexedSeqLike
iterator, isEmpty, forall, exists, find, foldLeft, foldRight, reduceLeft, reduceRight, zip, zipWithIndex, slice, head, tail, last, init, take, drop, takeRight, dropRight, splitAt, takeWhile, dropWhile, span, sameElements, lengthCompare, segmentLength, indexWhere, lastIndexWhere, reverse, reverseIterator, startsWith, endsWith
Methods inherited from BufferLike
+:, -=, ++:, ++=:, append, appendAll, prepend, prependAll, prependAll, insert, trimStart, trimEnd, <<, ++=, +, +, ++, ++, -, -, --, --, readOnly
Methods inherited from Shrinkable
-=, --=, --=
Methods inherited from Growable
+=, ++=
Methods inherited from SeqLike
size, isDefinedAt, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, reverseMap, reversedElements, startsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, updated, +:, :+, padTo, sortWith, sortWith, sortBy, toSeq, indices, hashCode, equals, toString, findLastIndexOf, equalsWith, containsSlice, projection
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from IterableLike
elements, toIterable, zipAll, toStream, canEqual, first, firstOption
Methods inherited from GenericTraversableTemplate
newBuilder, genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableLike
repr, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, /:, :\, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, lastOption, copyToBuffer, copyToArray, toArray, toList, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, addString, withFilter
Methods inherited from AnyRef
getClass, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Additional Constructor Details
def this : ArrayBuffer[A]

Method Details
override def companion : GenericCompanion[ArrayBuffer]
The factory companion object that builds instances of class CC
Overrides
Buffer.companion, GenericTraversableTemplate.companion, ResizableArray.companion

def clear : Unit
Clear the contents of this builder
Overrides
BufferLike.clear, Builder.clear

override def sizeHint(len : Int) : Unit
Give a hint how many elements are expected to be added when the next `result` is called.
Overrides
Builder.sizeHint

def +=(elem : A) : ArrayBuffer[A]
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
BufferLike.+=, Builder.+=

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

def +=:(elem : A) : ArrayBuffer[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
BufferLike.+=:

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

def insertAll(n : Int, seq : Traversable[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
BufferLike.insertAll

override def remove(n : Int, count : Int) : Unit
Removes the element on a given index position. It takes time linear in the buffer size.
Parameters
n - the index which refers to the first element to delete.
count - the number of elemenets to delete
Throws
Predef.IndexOutOfBoundsException - if n is out of bounds.
Overrides
BufferLike.remove

def remove(n : Int) : A
Removes the element on a given index position
Parameters
n - the index which refers to the element to delete.
Returns
The element that was formerly at position `n`
Overrides
BufferLike.remove

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

def result : ArrayBuffer[A]
Returns collection resulting from this builder. The buffer's contents are undefined afterwards.
Overrides
Builder.result

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