scala.collection.mutable
A Buffer
implementation back up by a list. It provides constant time
prepend and append. Most other operations are linear.
the type of this list buffer's elements.
2.8
1
"Scala's Collection Library overview"
section on List Buffers
for more information.
The type implementing this traversable
The type implementing this traversable
A class supporting filtered operations.
Test two objects for inequality.
Test two objects for inequality.
true
if !(this == that), false otherwise.
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.
a hash value consistent with ==
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.
the traversable object.
a new collection consisting of all the elements of this collection and xs
.
(Changed in version 2.8.0) ++
creates a new buffer. Use ++=
to add an element from this buffer and return that buffer itself.
[use case] 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).
the element type of the returned collection.
the traversable to append.
a new collection of type That
which contains all elements
of this list buffer followed by all elements of 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)
the element type of the returned collection.
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
.
the traversable to append.
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
.
a new collection of type That
which contains all elements
of this list buffer followed by all elements of 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.
the element type of the returned collection.
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
.
the traversable to append.
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
.
a new list buffer which contains all elements of this list buffer
followed by all elements of that
.
[use case] 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.
the element type of the returned collection.
the traversable to append.
a new collection of type That
which contains all elements
of this list buffer followed by all elements of 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)
the element type of the returned collection.
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
.
the traversable to append.
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
.
a new collection of type That
which contains all elements
of this list buffer followed by all elements of that
.
Appends all elements produced by a TraversableOnce to this list buffer.
Appends all elements produced by a TraversableOnce to this list buffer.
the list buffer itself.
Prepends elements to this buffer.
Prepends elements to this buffer.
the TraversableOnce containing the elements to prepend.
the buffer itself.
[use case] A copy of the list buffer with an element prepended.
A copy of the list buffer with an element prepended.
the prepended element
a new collection of type That
consisting of elem
followed
by all elements of this list buffer.
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)
the element type of the returned list buffer.
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
.
the prepended element
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
.
a new collection of type That
consisting of elem
followed
by all elements of this list buffer.
Appends a single element to this buffer.
Appends a single element to this buffer. This operation takes constant time.
the element to append.
this list buffer.
Appends two or more elements to this list buffer.
Appends two or more elements to this list buffer.
the first element to append.
the second element to append.
the remaining elements to append.
the list buffer itself
Prepends a single element to this buffer.
Prepends a single element to this buffer. This operation takes constant time.
the element to prepend.
this list buffer.
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.
the first element to remove.
the second element to remove.
the remaining elements to remove.
a new collection consisting of all the elements of this collection except
elem1
, elem2
and those in elems
.
(Changed in version 2.8.0) -
creates a new buffer. Use -=
to remove an element from this buffer and return that buffer itself.
Creates a new collection with all the elements of this collection except elem
.