scala.collection.mutable

Stack

class Stack[A] extends Seq[A] with Cloneable[Stack[A]]

A stack implements a data structure which allows to store and retrieve objects in a last-in-first-out (LIFO) fashion .

A

type of the elements contained in this stack .

go to: companion
known subclasses: SynchronizedStack, StackProxy
source: Stack.scala
    version
  1. 2 . 8

    since
  1. 1

    authors:
  1. Martin Odersky

  2. ,
  3. Matthias Zenger

Inherited

  1. Hide All
  2. Show all
  1. Cloneable
  2. Seq
  3. SeqLike
  4. Iterable
  5. IterableLike
  6. Equals
  7. Traversable
  8. GenericTraversableTemplate
  9. TraversableLike
  10. TraversableOnce
  11. HasNewBuilder
  12. PartialFunction
  13. Function1
  14. AnyRef
  15. Any

Visibility

  1. Public
  2. All

Instance constructors

  1. new Stack()

Type Members

  1. type Self = Seq[A]

    The type implementing this traversable

  2. class WithFilter extends AnyRef

    A class supporting filtered operations .

Value Members

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

  2. def !=(arg0: Any): Boolean

    o != arg0 is the same as !(o == (arg0)).

  3. def ##(): Int

  4. def $asInstanceOf[T0](): T0

  5. def $isInstanceOf[T0](): Boolean

  6. def ++(that: TraversableOnce[A]): Stack[A]

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

  7. def ++[B >: A, That](that: TraversableOnce[B])(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Concatenates this stack with the elements of a traversable collection .

  8. def ++=(xs: TraversableOnce[A]): Stack[A]

  9. def +:(elem: A): Stack[A]

    [use case] Prepends an element to this stack

  10. def +:[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Prepends an element to this stack

  11. def /:[B](z: B)(op: (B, A) ⇒ B): B

    Applies a binary operator to a start value and all elements of this stack, going left to right .

  12. def :+(elem: A): Stack[A]

    [use case] Appends an element to this stack

  13. def :+[B >: A, That](elem: B)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Appends an element to this stack

  14. def :\[B](z: B)(op: (A, B) ⇒ B): B

    Applies a binary operator to all elements of this stack and a start value, going right to left .

  15. def ==(arg0: AnyRef): Boolean

    o == arg0 is the same as if (o eq null) arg0 eq null else o.equals(arg0).

  16. def ==(arg0: Any): Boolean

    o == arg0 is the same as o.equals(arg0).

  17. def addString(b: StringBuilder): StringBuilder

    Appends all elements of this stack to a string builder .

  18. def addString(b: StringBuilder, sep: String): StringBuilder

    Appends all elements of this stack to a string builder using a separator string .

  19. def addString(b: StringBuilder, start: String, sep: String, end: String): StringBuilder

    Appends all elements of this stack to a string builder using start, end, and separator strings .

  20. def andThen[C](k: (A) ⇒ C): PartialFunction[Int, C]

    Composes this partial function with a transformation function that gets applied to results of this partial function .

  21. def apply(index: Int): A

    Retrieve n'th element from stack, where top of stack has index 0@return the element of this stack at index idx, where 0 indicates the first element.

  22. def asInstanceOf[T0]: T0

    This method is used to cast the receiver object to be of type T0.

  23. def canEqual(that: Any): Boolean

    Method called from equality methods, so that user-defined subclasses can refuse to be equal to other collections of the same kind .

  24. def clear(): Unit

    Removes all elements from the stack .

  25. def clone(): Stack[A]

    This method clones the stack .

  26. def collect[B](pf: PartialFunction[A, B]): Stack[B]

    [use case] Builds a new collection by applying a partial function to all elements of this stack on which the function is defined .

  27. def collect[B, That](pf: PartialFunction[A, B])(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Builds a new collection by applying a partial function to all elements of this stack on which the function is defined .

  28. def companion: GenericCompanion[Seq[A][A]]

    The factory companion object that builds instances of class Stack .

  29. def compose[A](g: (A) ⇒ Int): (A) ⇒ A

    (f compose g)(x) == f(g(x))

  30. def contains(elem: Any): Boolean

    Tests whether this stack contains a given value as an element .

  31. def containsSlice[B](that: Seq[B]): Boolean

    Tests whether this stack contains a given sequence as a slice .

  32. def copyToArray(xs: Array[A], start: Int, len: Int): Unit

    [use case] Copies elements of this stack to an array .

  33. def copyToArray[B >: A](xs: Array[B], start: Int, len: Int): Unit

    Copies elements of this stack to an array .

  34. def copyToArray(xs: Array[A]): Unit

    [use case] Copies values of this stack to an array .

  35. def copyToArray[B >: A](xs: Array[B]): Unit

    Copies values of this stack to an array .

  36. def copyToArray(xs: Array[A], start: Int): Unit

    [use case] Copies values of this stack to an array .

  37. def copyToArray[B >: A](xs: Array[B], start: Int): Unit

    Copies values of this stack to an array .

  38. def copyToBuffer[B >: A](dest: Buffer[B]): Unit

    Copies all elements of this stack to a buffer .

  39. def corresponds[B](that: Seq[B])(p: (A, B) ⇒ Boolean): Boolean

    Tests whether every element of this stack relates to the corresponding element of another sequence by satisfying a test predicate .

  40. def count(p: (A) ⇒ Boolean): Int

    Counts the number of elements in the stack which satisfy a predicate .

  41. def diff(that: Seq[A]): Stack[A]

    [use case] Computes the multiset difference between this stack and another sequence .

  42. def diff[B >: A](that: Seq[B]): Seq[A]

    Computes the multiset difference between this stack and another sequence .

  43. def distinct: Seq[A]

    Builds a new stack from this stack without any duplicate elements .

  44. def drop(n: Int): Seq[A]

    Selects all elements except first n ones.

  45. def dropRight(n: Int): Seq[A]

    Selects all elements except last n ones.

  46. def dropWhile(p: (A) ⇒ Boolean): Seq[A]

    Drops longest prefix of elements that satisfy a predicate .

  47. def elements: Iterator[A]

  48. var elems: List[A]

  49. def endsWith[B](that: Seq[B]): Boolean

    Tests whether this stack ends with the given sequence .

  50. def eq(arg0: AnyRef): Boolean

    This method is used to test whether the argument (arg0) is a reference to the receiver object (this).

  51. def equals(that: Any): Boolean

    The equality method defined in AnyRef.

  52. def equalsWith[B](that: Seq[B])(f: (A, B) ⇒ Boolean): Boolean

    Tests whether every element of this stack relates to the corresponding element of another sequence by satisfying a test predicate .

  53. def exists(p: (A) ⇒ Boolean): Boolean

    Tests whether a predicate holds for some of the elements of this stack .

  54. def filter(p: (A) ⇒ Boolean): Seq[A]

    Selects all elements of this stack which satisfy a predicate .

  55. def filterNot(p: (A) ⇒ Boolean): Seq[A]

    Selects all elements of this stack which do not satisfy a predicate .

  56. def finalize(): Unit

    This method is called by the garbage collector on the receiver object when garbage collection determines that there are no more references to the object .

  57. def find(p: (A) ⇒ Boolean): Option[A]

    Finds the first element of the stack satisfying a predicate, if any .

  58. def findIndexOf(p: (A) ⇒ Boolean): Int

    Returns index of the first element satisfying a predicate, or -1.

  59. def findLastIndexOf(p: (A) ⇒ Boolean): Int

    Returns index of the last element satisfying a predicate, or -1 .

  60. def first: A

  61. def firstOption: Option[A]

    None if iterable is empty.

  62. def flatMap[B](f: (A) ⇒ Traversable[B]): Stack[B]

    [use case] Builds a new collection by applying a function to all elements of this stack and concatenating the results .

  63. def flatMap[B, That](f: (A) ⇒ Traversable[B])(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Builds a new collection by applying a function to all elements of this stack and concatenating the results .

  64. def flatten[B]: Stack[B]

    [use case] Converts this stack of traversable collections into a stack in which all element collections are concatenated .

  65. def flatten[B](implicit asTraversable: (A) ⇒ Traversable[B]): Seq[B]

    Converts this stack of traversable collections into a stack in which all element collections are concatenated .

  66. def foldLeft[B](z: B)(op: (B, A) ⇒ B): B

    Applies a binary operator to a start value and all elements of this stack, going left to right .

  67. def foldRight[B](z: B)(op: (A, B) ⇒ B): B

    Applies a binary operator to all elements of this stack and a start value, going right to left .

  68. def forall(p: (A) ⇒ Boolean): Boolean

    Tests whether a predicate holds for all elements of this stack .

  69. def foreach(f: (A) ⇒ Unit): Unit

    [use case] Applies a function f to all elements of this stack.

  70. def foreach[U](f: (A) ⇒ U): Unit

    Applies a function f to all elements of this stack.

  71. def genericBuilder[B]: Builder[B, Seq[B]]

    The generic builder that builds instances of Stack at arbitrary element types .

  72. def getClass(): java.lang.Class[_ <: java.lang.Object]

    Returns a representation that corresponds to the dynamic class of the receiver object .

  73. def groupBy[K](f: (A) ⇒ K): Map[K, Seq[A]]

    Partitions this stack into a map of stacks according to some discriminator function .

  74. def grouped(size: Int): Iterator[Seq[A]]

    Partitions elements in fixed size stacks .

  75. def hasDefiniteSize: Boolean

    Tests whether this stack is known to have a finite size .

  76. def hashCode(): Int

    Hashcodes for Stack produce a value from the hashcodes of all the elements of the stack .

  77. def head: A

    Selects the first element of this stack .

  78. def headOption: Option[A]

    Optionally selects the first element .

  79. def indexOf(elem: A, from: Int): Int

    [use case] Finds index of first occurrence of some value in this stack after or at some start index .

  80. def indexOf[B >: A](elem: B, from: Int): Int

    Finds index of first occurrence of some value in this stack after or at some start index .

  81. def indexOf(elem: A): Int

    [use case] Finds index of first occurrence of some value in this stack .

  82. def indexOf[B >: A](elem: B): Int

    Finds index of first occurrence of some value in this stack .

  83. def indexOfSlice[B >: A](that: Seq[B], from: Int): Int

    Finds first index after or at a start index where this stack contains a given sequence as a slice .

  84. def indexOfSlice[B >: A](that: Seq[B]): Int

    Finds first index where this stack contains a given sequence as a slice .

  85. def indexWhere(p: (A) ⇒ Boolean, from: Int): Int

    Finds index of the first element satisfying some predicate after or at some start index .

  86. def indexWhere(p: (A) ⇒ Boolean): Int

    Finds index of first element satisfying some predicate .

  87. def indices: Range

    Produces the range of all indices of this sequence .

  88. def init: Seq[A]

    Selects all elements except the last .

  89. def intersect(that: Seq[A]): Stack[A]

    [use case] Computes the multiset intersection between this stack and another sequence .

  90. def intersect[B >: A](that: Seq[B]): Seq[A]

    Computes the multiset intersection between this stack and another sequence .

  91. def isDefinedAt(idx: Int): Boolean

    Tests whether this stack contains given index .

  92. def isEmpty: Boolean

    Checks if the stack is empty .

  93. def isInstanceOf[T0]: Boolean

    This method is used to test whether the dynamic type of the receiver object is T0.

  94. def isTraversableAgain: Boolean

    Tests whether this stack can be repeatedly traversed .

  95. def iterator: Iterator[A]

    Returns an iterator over all elements on the stack .

  96. def last: A

    Selects the last element .

  97. def lastIndexOf(elem: A, end: Int): Int

    [use case] Finds index of last occurrence of some value in this stack before or at a given end index .

  98. def lastIndexOf[B >: A](elem: B, end: Int): Int

    Finds index of last occurrence of some value in this stack before or at a given end index .

  99. def lastIndexOf(elem: A): Int

    [use case] Finds index of last occurrence of some value in this stack .

  100. def lastIndexOf[B >: A](elem: B): Int

    Finds index of last occurrence of some value in this stack .

  101. def lastIndexOfSlice[B >: A](that: Seq[B], end: Int): Int

    Finds last index before or at a given end index where this stack contains a given sequence as a slice .

  102. def lastIndexOfSlice[B >: A](that: Seq[B]): Int

    Finds last index where this stack contains a given sequence as a slice .

  103. def lastIndexWhere(p: (A) ⇒ Boolean, end: Int): Int

    Finds index of last element satisfying some predicate before or at given end index .

  104. def lastIndexWhere(p: (A) ⇒ Boolean): Int

    Finds index of last element satisfying some predicate .

  105. def lastOption: Option[A]

    Optionally selects the last element .

  106. def length: Int

    The number of elements in the stack@return the number of elements in this stack .

  107. def lengthCompare(len: Int): Int

    Compares the length of this stack to a test value .

  108. def lift: (Int) ⇒ Option[A]

    Turns this partial function into an plain function returning an Option result.

  109. def map[B](f: (A) ⇒ B): Stack[B]

    [use case] Builds a new collection by applying a function to all elements of this stack .

  110. def map[B, That](f: (A) ⇒ B)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Builds a new collection by applying a function to all elements of this stack .

  111. def max: A

    [use case] Finds the largest element .

  112. def max[B >: A](implicit cmp: Ordering[B]): A

    Finds the largest element .

  113. def min: A

    [use case] Finds the smallest element .

  114. def min[B >: A](implicit cmp: Ordering[B]): A

    Finds the smallest element .

  115. def mkString: String

    Displays all elements of this stack in a string .

  116. def mkString(sep: String): String

    Displays all elements of this stack in a string using a separator string .

  117. def mkString(start: String, sep: String, end: String): String

    Displays all elements of this stack in a string using start, end, and separator strings .

  118. def ne(arg0: AnyRef): Boolean

    o.ne(arg0) is the same as !(o.eq(arg0)).

  119. def newBuilder: Builder[A, Seq[A]]

    The builder that builds instances of type Stack[A]

  120. def nonEmpty: Boolean

    Tests whether the stack is not empty .

  121. def notify(): Unit

    Wakes up a single thread that is waiting on the receiver object's monitor .

  122. def notifyAll(): Unit

    Wakes up all threads that are waiting on the receiver object's monitor .

  123. def orElse[A1 <: Int, B1 >: A](that: PartialFunction[A1, B1]): PartialFunction[A1, B1]

    Composes this partial function with a fallback partial function which gets applied where this partial function is not defined .

  124. def padTo(len: Int, elem: A): Stack[A]

    [use case] Appends an element value to this stack until a given target length is reached .

  125. def padTo[B >: A, That](len: Int, elem: B)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Appends an element value to this stack until a given target length is reached .

  126. def partition(p: (A) ⇒ Boolean): (Seq[A], Seq[A])

    Partitions this stack in two stacks according to a predicate .

  127. def patch(from: Int, that: Seq[A], replaced: Int): Stack[A]

    [use case] Produces a new stack where a slice of elements in this stack is replaced by another sequence .

  128. def patch[B >: A, That](from: Int, patch: Seq[B], replaced: Int)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Produces a new stack where a slice of elements in this stack is replaced by another sequence .

  129. def pop(): A

    Removes the top element from the stack .

  130. def prefixLength(p: (A) ⇒ Boolean): Int

    Returns the length of the longest prefix whose elements all satisfy some predicate .

  131. def product: Int

    [use case] Multiplies up the elements of this collection .

  132. def product[B >: A](implicit num: Numeric[B]): B

    Multiplies up the elements of this collection .

  133. def projection: SeqView[A, Seq[A]]

    returns a projection that can be used to call non-strict filter, map, and flatMap methods that build projections of the collection .

  134. def push(elem1: A, elem2: A, elems: A*): Stack[A]

    Push two or more elements onto the stack .

  135. def push(elem: A): Stack[A]

    Push an element on the stack .

  136. def pushAll(xs: TraversableOnce[A]): Stack[A]

    Push all elements in the given traversable object onto the stack .

  137. def reduceLeft[B >: A](op: (B, A) ⇒ B): B

    Applies a binary operator to all elements of this stack, going left to right .

  138. def reduceLeftOption[B >: A](op: (B, A) ⇒ B): Option[B]

    Optionally applies a binary operator to all elements of this stack, going left to right .

  139. def reduceRight[B >: A](op: (A, B) ⇒ B): B

    Applies a binary operator to all elements of this stack, going right to left .

  140. def reduceRightOption[B >: A](op: (A, B) ⇒ B): Option[B]

    Optionally applies a binary operator to all elements of this stack, going right to left .

  141. def repr: Seq[A]

    The collection of type stack underlying this TraversableLike object.

  142. def reverse: Seq[A]

    Returns new stack wih elements in reversed order .

  143. def reverseIterator: Iterator[A]

    An iterator yielding elements in reversed order .

  144. def reverseMap[B](f: (A) ⇒ B): Stack[B]

    [use case] Builds a new collection by applying a function to all elements of this stack and collecting the results in reversed order .

  145. def reverseMap[B, That](f: (A) ⇒ B)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Builds a new collection by applying a function to all elements of this stack and collecting the results in reversed order .

  146. def reversed: List[A]

  147. def reversedElements: Iterator[A]

  148. def sameElements(that: Iterable[A]): Boolean

    [use case] Checks if the other iterable collection contains the same elements in the same order as this stack .

  149. def sameElements[B >: A](that: Iterable[B]): Boolean

    Checks if the other iterable collection contains the same elements in the same order as this stack .

  150. def scanLeft[B, That](z: B)(op: (B, A) ⇒ B)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Produces a collection containing cummulative results of applying the operator going left to right .

  151. def scanRight[B, That](z: B)(op: (A, B) ⇒ B)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Produces a collection containing cummulative results of applying the operator going right to left .

  152. def segmentLength(p: (A) ⇒ Boolean, from: Int): Int

    Computes length of longest segment whose elements all satisfy some predicate .

  153. def size: Int

    The size of this stack, equivalent to length.

  154. def slice(from: Int, until: Int): Seq[A]

    Selects an interval of elements .

  155. def sliding[B >: A](size: Int, step: Int): Iterator[Seq[A]]

  156. def sliding[B >: A](size: Int): Iterator[Seq[A]]

    Groups elements in fixed size blocks by passing a "sliding window" over them (as opposed to partitioning them, as is done in grouped .

  157. def sortBy[B](f: (A) ⇒ B)(implicit ord: Ordering[B]): Seq[A]

    Sorts this Stack according to the Ordering which results from transforming an implicitly given Ordering with a transformation function .

  158. def sortWith(lt: (A, A) ⇒ Boolean): Seq[A]

    Sorts this stack according to a comparison function .

  159. def sorted[B >: A](implicit ord: Ordering[B]): Seq[A]

    Sorts this stack according to an Ordering .

  160. def span(p: (A) ⇒ Boolean): (Seq[A], Seq[A])

    Splits this stack into a prefix/suffix pair according to a predicate .

  161. def splitAt(n: Int): (Seq[A], Seq[A])

    Splits this stack into two at a given position .

  162. def startsWith[B](that: Seq[B]): Boolean

    Tests whether this stack starts with the given sequence .

  163. def startsWith[B](that: Seq[B], offset: Int): Boolean

    Tests whether this stack contains the given sequence at a given index .

  164. def stringPrefix: String

    Defines the prefix of this object's toString representation.

  165. def sum: Int

    [use case] Sums up the elements of this collection .

  166. def sum[B >: A](implicit num: Numeric[B]): B

    Sums up the elements of this collection .

  167. def synchronized[T0](arg0: T0): T0

  168. def tail: Seq[A]

    Selects all elements except the first .

  169. def take(n: Int): Seq[A]

    Selects first n elements.

  170. def takeRight(n: Int): Seq[A]

    Selects last n elements.

  171. def takeWhile(p: (A) ⇒ Boolean): Seq[A]

    Takes longest prefix of elements that satisfy a predicate .

  172. def thisCollection: Seq[A]

    The underlying collection seen as an instance of Stack.

  173. def toArray: Array[A]

    [use case] Converts this stack to an array .

  174. def toArray[B >: A](implicit arg0: ClassManifest[B]): Array[B]

    Converts this stack to an array .

  175. def toCollection(repr: Seq[A]): Seq[A]

    A conversion from collections of type Repr to Stack objects.

  176. def toIndexedSeq[B >: A]: IndexedSeq[B]

    Converts this stack to an indexed sequence .

  177. def toIterable: Iterable[A]

    Converts this stack to an iterable collection .

  178. def toIterator: Iterator[A]

    Returns an Iterator over the elements in this stack .

  179. def toList: List[A]

    Creates a list of all stack elements in LIFO order .

  180. def toMap[T, U](implicit ev: <:<[A, (T, U)]): Map[T, U]

    Converts this stack to a map .

  181. def toSeq: Seq[A]

    Converts this stack to a sequence .

  182. def toSet[B >: A]: Set[B]

    Converts this stack to a set .

  183. def toStream: Stream[A]

    Converts this stack to a stream .

  184. def toString(): String

    Converts this stack to a string .

  185. def toTraversable: Traversable[A]

    Converts this stack to an unspecified Traversable .

  186. def top: A

    Returns the top element of the stack .

  187. def transpose[B](implicit asTraversable: (A) ⇒ Traversable[B]): Seq[Seq[B]]

    Transposes this stack of traversable collections into a stack of stacks .

  188. def union(that: Seq[A]): Stack[A]

    [use case] Produces a new sequence which contains all elements of this stack and also all elements of a given sequence .

  189. def union[B >: A, That](that: Seq[B])(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    Produces a new sequence which contains all elements of this stack and also all elements of a given sequence .

  190. def unzip[A1, A2](implicit asPair: (A) ⇒ (A1, A2)): (Seq[A1], Seq[A2])

    Converts this stack of pairs into two collections of the first and second halfs of each pair .

  191. def updated(index: Int, elem: A): Stack[A]

    [use case] A copy of this stack with one single replaced element .

  192. def updated[B >: A, That](index: Int, elem: B)(implicit bf: CanBuildFrom[Seq[A], B, That]): That

    A copy of this stack with one single replaced element .

  193. def view(from: Int, until: Int): SeqView[A, Seq[A]]

    Creates a non-strict view of a slice of this stack .

  194. def view: SeqView[A, Seq[A]]

    Creates a non-strict view of this stack .

  195. def wait(): Unit

  196. def wait(arg0: Long, arg1: Int): Unit

  197. def wait(arg0: Long): Unit

  198. def withFilter(p: (A) ⇒ Boolean): WithFilter

    Creates a non-strict filter of this stack .

  199. def zip[B](that: Iterable[B]): Stack[(A, B)]

    [use case] Returns a stack formed from this stack and another iterable collection by combining corresponding elements in pairs .

  200. def zip[A1 >: A, B, That](that: Iterable[B])(implicit bf: CanBuildFrom[Seq[A], (A1, B), That]): That

    Returns a stack formed from this stack and another iterable collection by combining corresponding elements in pairs .

  201. def zipAll[B](that: Iterable[B], thisElem: A, thatElem: B): Stack[(A, B)]

    [use case] Returns a stack formed from this stack and another iterable collection by combining corresponding elements in pairs .

  202. def zipAll[B, A1 >: A, That](that: Iterable[B], thisElem: A1, thatElem: B)(implicit bf: CanBuildFrom[Seq[A], (A1, B), That]): That

    Returns a stack formed from this stack and another iterable collection by combining corresponding elements in pairs .

  203. def zipWithIndex: Stack[(A, Int)]

    [use case] Zips this stack with its indices .

  204. def zipWithIndex[A1 >: A, That](implicit bf: CanBuildFrom[Seq[A], (A1, Int), That]): That

    Zips this stack with its indices .