scala.collection.mutable

class ArrayBuffer

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

@serializable

class ArrayBuffer[A](protected val override initialSize : Int)
extends Buffer[A] with TraversableClass[A, ArrayBuffer] with BufferTemplate[A, ArrayBuffer[A]] with VectorTemplate[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
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]
Prepends 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]
Appends 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]
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) : ArrayBuffer[A]
Appends a single element to this buffer and returns the identity of the buffer. It takes constant time.
def clear : Unit
Clear the contents of this builder
override def clone : ArrayBuffer[A]
Return a clone of this buffer.
override def companion : Companion[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.
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 remove (n : Int) : A
Removes the element on a given index position
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, copyToArray, foreach, reduceToSize, ensureSize, swap, copy
Methods inherited from MutableVectorTemplate
view, view
Methods inherited from Builder
mapResult
Methods inherited from VectorTemplate
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, copyToArray, lengthCompare, segmentLength, indexWhere, lastIndexWhere, reverse, reverseIterator, startsWith, endsWith, equals
Methods inherited from BufferTemplate
-=, ++:, append, appendAll, prepend, prependAll, prependAll, insert, trimStart, trimEnd, <<, ++=, +, +, ++, ++, -, -, --, --
Methods inherited from Shrinkable
-=, --=, --=
Methods inherited from Growable
+=, ++=
Methods inherited from Unhashable
hashCode, identityHashCode
Methods inherited from SequenceTemplate
size, isDefinedAt, zipAll, prefixLength, indexWhere, findIndexOf, indexOf, indexOf, lastIndexOf, lastIndexOf, lastIndexWhere, reversedElements, startsWith, indexOfSeq, indexOfSeq, lastIndexOfSeq, lastIndexOfSeq, contains, union, diff, intersect, removeDuplicates, patch, padTo, toSequence, indices, toString, sortWith, findLastIndexOf, slice, equalsWith, containsSlice, projection
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from IterableTemplate
elements, toIterable, toStream, first, firstOption, toSeq
Methods inherited from TraversableClass
newBuilder, genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableTemplate
thisCollection, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterMap, filterNot, remove, partition, groupBy, count, /:, :\, reduceLeftOption, reduceRightOption, headOption, lastOption, copyToBuffer, toArray, toList, toSet, mkString, mkString, mkString, addString, addString, addString
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 : Companion[ArrayBuffer]
The factory companion object that builds instances of class CC
Overrides
Buffer.companion, TraversableClass.companion, ResizableArray.companion

def clear : Unit
Clear the contents of this builder
Overrides
BufferTemplate.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
BufferTemplate.+=, 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
BufferTemplate.+:

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
BufferTemplate.++:

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
BufferTemplate.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
Returns
the updated array buffer.
Throws
Predef.IndexOutOfBoundsException - if n is out of bounds.
Overrides
BufferTemplate.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
BufferTemplate.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
BufferTemplate.stringPrefix