spacer

scala.collection.mutable

ListBuffer

final class ListBuffer[A] extends Buffer[A] with GenericTraversableTemplate[A, ListBuffer] with BufferLike[A, ListBuffer[A]] with Builder[A, List[A]] with SeqForwarder[A] with Serializable

A Buffer implementation back up by a list. It provides constant time prepend and append. Most other operations are linear.

A

the type of this list buffer's elements.

Annotations
@SerialVersionUID( uid = 3419063961353022661L )
Source
ListBuffer.scala
Version

2.8

Since

1

See also

"Scala's Collection Library overview" section on List Buffers for more information.

Linear Supertypes
Serializable, Serializable, SeqForwarder[A], IterableForwarder[A], TraversableForwarder[A], Builder[A, List[A]], Buffer[A], BufferLike[A, ListBuffer[A]], Subtractable[A, ListBuffer[A]], Scriptable[A], Shrinkable[A], Growable[A], Seq[A], SeqLike[A, ListBuffer[A]], Cloneable[ListBuffer[A]], Seq[A], SeqLike[A, ListBuffer[A]], GenSeq[A], GenSeqLike[A, ListBuffer[A]], PartialFunction[Int, A], (Int) ⇒ A, Iterable[A], Iterable[A], IterableLike[A, ListBuffer[A]], Equals, GenIterable[A], GenIterableLike[A, ListBuffer[A]], Traversable[A], Mutable, Traversable[A], GenTraversable[A], GenericTraversableTemplate[A, ListBuffer], TraversableLike[A, ListBuffer[A]], GenTraversableLike[A, ListBuffer[A]], Parallelizable[A, ParSeq[A]], TraversableOnce[A], GenTraversableOnce[A], FilterMonadic[A, ListBuffer[A]], HasNewBuilder[A, ListBuffer[A]], AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. ListBuffer
  2. Serializable
  3. Serializable
  4. SeqForwarder
  5. IterableForwarder
  6. TraversableForwarder
  7. Builder
  8. Buffer
  9. BufferLike
  10. Subtractable
  11. Scriptable
  12. Shrinkable
  13. Growable
  14. Seq
  15. SeqLike
  16. Cloneable
  17. Seq
  18. SeqLike
  19. GenSeq
  20. GenSeqLike
  21. PartialFunction
  22. Function1
  23. Iterable
  24. Iterable
  25. IterableLike
  26. Equals
  27. GenIterable
  28. GenIterableLike
  29. Traversable
  30. Mutable
  31. Traversable
  32. GenTraversable
  33. GenericTraversableTemplate
  34. TraversableLike
  35. GenTraversableLike
  36. Parallelizable
  37. TraversableOnce
  38. GenTraversableOnce
  39. FilterMonadic
  40. HasNewBuilder
  41. AnyRef
  42. Any
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ListBuffer()

Type Members

  1. type Self = ListBuffer[A]

    The type implementing this traversable

    The type implementing this traversable

    Attributes
    protected
    Definition Classes
    TraversableLike
  2. class WithFilter extends FilterMonadic[A, Repr]

    A class supporting filtered operations.

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Test two objects for inequality.

    Test two objects for inequality.

    returns

    true if !(this == that), false otherwise.

    Definition Classes
    Any
  3. final def ##(): Int

    Equivalent to x.hashCode except for boxed numeric types.

    Equivalent to x.hashCode except for boxed numeric types. For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them.

    returns

    a hash value consistent with ==

    Definition Classes
    AnyRef → Any
  4. def ++(xs: GenTraversableOnce[A]): ListBuffer[A]

    Creates a new collection containing both the elements of this collection and the provided traversable object.

    Creates a new collection containing both the elements of this collection and the provided traversable object.

    xs

    the traversable object.

    returns

    a new collection consisting of all the elements of this collection and xs.

    Definition Classes
    BufferLike
    Annotations
    @migration
    Migration

    (Changed in version 2.8.0) ++ creates a new buffer. Use ++= to add an element from this buffer and return that buffer itself.

  5. abstract def ++[B](that: GenTraversableOnce[B]): ListBuffer[B]

    [use case] Returns a new list buffer containing the elements from the left hand operand followed by the elements from the right hand operand.

    [use case]

    Returns a new list buffer containing the elements from the left hand operand followed by the elements from the right hand operand. The element type of the list buffer is the most specific superclass encompassing the element types of the two operands (see example).

    B

    the element type of the returned collection.

    that

    the traversable to append.

    returns

    a new collection of type That which contains all elements of this list buffer followed by all elements of that.

    Definition Classes
    GenTraversableLike
  6. def ++[B >: A, That](that: GenTraversableOnce[B])(implicit bf: CanBuildFrom[ListBuffer[A], B, That]): That

    Returns a new list buffer containing the elements from the left hand operand followed by the elements from the right hand operand.

    Returns a new list buffer containing the elements from the left hand operand followed by the elements from the right hand operand. The element type of the list buffer is the most specific superclass encompassing the element types of the two operands (see example).

    Example:

        scala> val a = LinkedList(1)
        a: scala.collection.mutable.LinkedList[Int] = LinkedList(1)
    
        scala> val b = LinkedList(2)
        b: scala.collection.mutable.LinkedList[Int] = LinkedList(2)
    
        scala> val c = a ++ b
        c: scala.collection.mutable.LinkedList[Int] = LinkedList(1, 2)
    
        scala> val d = LinkedList('a')
        d: scala.collection.mutable.LinkedList[Char] = LinkedList(a)
    
        scala> val e = c ++ d
        e: scala.collection.mutable.LinkedList[AnyVal] = LinkedList(1, 2, a)
    
    B

    the element type of the returned collection.

    That

    the class of the returned collection. In the standard library configuration, That is always ListBuffer[B] because an implicit of type CanBuildFrom[ListBuffer, B, ListBuffer[B]] is defined in object ListBuffer.

    that

    the traversable to append.

    bf

    an implicit value of class CanBuildFrom which determines the result class That from the current representation type Repr and the new element type B. This is usually the canBuildFrom value defined in object ListBuffer.

    returns

    a new collection of type That which contains all elements of this list buffer followed by all elements of that.

    Definition Classes
    TraversableLike → GenTraversableLike
  7. def ++:[B >: A, That](that: Traversable[B])(implicit bf: CanBuildFrom[ListBuffer[A], B, That]): That

    As with ++, returns a new collection containing the elements from the left operand followed by the elements from the right operand.

    As with ++, returns a new collection containing the elements from the left operand followed by the elements from the right operand. It differs from ++ in that the right operand determines the type of the resulting collection rather than the left one.

    Example:

        scala> val x = List(1)
        x: List[Int] = List(1)
    
        scala> val y = LinkedList(2)
        y: scala.collection.mutable.LinkedList[Int] = LinkedList(2)
    
        scala> val z = x ++: y
        z: scala.collection.mutable.LinkedList[Int] = LinkedList(1, 2)
    

    This overload exists because: for the implementation of ++: we should reuse that of ++ because many collections override it with more efficient versions.

    Since TraversableOnce has no ++ method, we have to implement that directly, but Traversable and down can use the overload.

    B

    the element type of the returned collection.

    That

    the class of the returned collection. In the standard library configuration, That is always ListBuffer[B] because an implicit of type CanBuildFrom[ListBuffer, B, ListBuffer[B]] is defined in object ListBuffer.

    that

    the traversable to append.

    bf

    an implicit value of class CanBuildFrom which determines the result class That from the current representation type Repr and the new element type B. This is usually the canBuildFrom value defined in object ListBuffer.

    returns

    a new list buffer which contains all elements of this list buffer followed by all elements of that.

    Definition Classes
    TraversableLike
  8. abstract def ++:[B](that: TraversableOnce[B]): ListBuffer[B]

    [use case] Concatenates this list buffer with the elements of a traversable collection.

    [use case]

    Concatenates this list buffer with the elements of a traversable collection. It differs from ++ in that the right operand determines the type of the resulting collection rather than the left one.

    B

    the element type of the returned collection.

    that

    the traversable to append.

    returns

    a new collection of type That which contains all elements of this list buffer followed by all elements of that.

    Definition Classes
    TraversableLike
  9. def ++:[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[ListBuffer[A], B, That]): That

    Concatenates this list buffer with the elements of a traversable collection.

    Concatenates this list buffer with the elements of a traversable collection. It differs from ++ in that the right operand determines the type of the resulting collection rather than the left one.

    Example:

        scala> val x = List(1)
        x: List[Int] = List(1)
    
        scala> val y = LinkedList(2)
        y: scala.collection.mutable.LinkedList[Int] = LinkedList(2)
    
        scala> val z = x ++: y
        z: scala.collection.mutable.LinkedList[Int] = LinkedList(1, 2)
    
    B

    the element type of the returned collection.

    That

    the class of the returned collection. In the standard library configuration, That is always ListBuffer[B] because an implicit of type CanBuildFrom[ListBuffer, B, ListBuffer[B]] is defined in object ListBuffer.

    that

    the traversable to append.

    bf

    an implicit value of class CanBuildFrom which determines the result class That from the current representation type Repr and the new element type B. This is usually the canBuildFrom value defined in object ListBuffer.

    returns

    a new collection of type That which contains all elements of this list buffer followed by all elements of that.

    Definition Classes
    TraversableLike
  10. def ++=(xs: TraversableOnce[A]): ListBuffer.this.type

    Appends all elements produced by a TraversableOnce to this list buffer.

    Appends all elements produced by a TraversableOnce to this list buffer.

    returns

    the list buffer itself.

    Definition Classes
    ListBuffer → Growable
  11. def ++=:(xs: TraversableOnce[A]): ListBuffer.this.type

    Prepends elements to this buffer.

    Prepends elements to this buffer.

    xs

    the TraversableOnce containing the elements to prepend.

    returns

    the buffer itself.

    Definition Classes
    ListBuffer → BufferLike
  12. abstract def +:(elem: A): ListBuffer[A]

    [use case] A copy of the list buffer with an element prepended.

    [use case]

    A copy of the list buffer with an element prepended.

    elem

    the prepended element

    returns

    a new collection of type That consisting of elem followed by all elements of this list buffer.

    Definition Classes
    GenSeqLike
  13. def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[ListBuffer[A], B, That]): That

    A copy of the list buffer with an element prepended.

    A copy of the list buffer with an element prepended.

    Note that :-ending operators are right associative (see example). Also, the original list buffer is not modified, so you will want to capture the result.

    Example:

         scala> val x = LinkedList(1)
         x: scala.collection.mutable.LinkedList[Int] = LinkedList(1)
    
         scala> val y = 2 +: x
         y: scala.collection.mutable.LinkedList[Int] = LinkedList(2, 1)
    
         scala> println(x)
         LinkedList(1)
    
    B

    the element type of the returned list buffer.

    That

    the class of the returned collection. In the standard library configuration, That is always ListBuffer[B] because an implicit of type CanBuildFrom[ListBuffer, B, ListBuffer[B]] is defined in object ListBuffer.

    elem

    the prepended element

    bf

    an implicit value of class CanBuildFrom which determines the result class That from the current representation type Repr and the new element type B. This is usually the canBuildFrom value defined in object ListBuffer.

    returns

    a new collection of type That consisting of elem followed by all elements of this list buffer.

    Definition Classes
    SeqLike → GenSeqLike
  14. def +=(x: A): ListBuffer.this.type

    Appends a single element to this buffer.

    Appends a single element to this buffer. This operation takes constant time.

    x

    the element to append.

    returns

    this list buffer.

    Definition Classes
    ListBuffer → Builder → BufferLike → Growable
  15. def +=(elem1: A, elem2: A, elems: A*): ListBuffer.this.type

    Appends two or more elements to this list buffer.

    Appends two or more elements to this list buffer.

    elem1

    the first element to append.

    elem2

    the second element to append.

    elems

    the remaining elements to append.

    returns

    the list buffer itself

    Definition Classes
    Growable
  16. def +=:(x: A): ListBuffer.this.type

    Prepends a single element to this buffer.

    Prepends a single element to this buffer. This operation takes constant time.

    x

    the element to prepend.

    returns

    this list buffer.

    Definition Classes
    ListBuffer → BufferLike
  17. def -(elem1: A, elem2: A, elems: A*): ListBuffer[A]

    Creates a new collection with all the elements of this collection except the two or more specified elements.

    Creates a new collection with all the elements of this collection except the two or more specified elements.

    elem1

    the first element to remove.

    elem2

    the second element to remove.

    elems

    the remaining elements to remove.

    returns

    a new collection consisting of all the elements of this collection except elem1, elem2 and those in elems.

    Definition Classes
    BufferLike → Subtractable
    Annotations
    @migration
    Migration

    (Changed in version 2.8.0) - creates a new buffer. Use -= to remove an element from this buffer and return that buffer itself.

  18. def -(elem: A): ListBuffer[A]

    Creates a new collection with all the elements of this collection except elem.

    Creates a new collection with all the elements of this collection except elem.

    elem

    the element to remove.

    returns

    a new collection consisting of all the elements of this collection except elem.

    Definition Classes
    BufferLike →
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.