Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# Stack

```
open class Stack<E : Any!> : Vector<E>
```

|---|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html) |||||
| ↳ | [java.util.AbstractCollection](https://developer.android.com/reference/kotlin/java/util/AbstractCollection)\<E\> ||||
|   | ↳ | [java.util.AbstractList](https://developer.android.com/reference/kotlin/java/util/AbstractList)\<E\> |||
|   |   | ↳ | [java.util.Vector](https://developer.android.com/reference/kotlin/java/util/Vector)\<E\> ||
|   |   |   | ↳ | [java.util.Stack](https://developer.android.com/reference/kotlin/java/util/Stack#) |

The `Stack` class represents a last-in-first-out (LIFO) stack of objects. It extends class `Vector` with five operations that allow a vector to be treated as a stack. The usual `push` and `pop` operations are provided, as well as a method to `peek` at the top item on the stack, a method to test for whether the stack is `empty`, and a method to `search` the stack for an item and discover how far it is from the top.

When a stack is first created, it contains no items.

A more complete and consistent set of LIFO stack operations is provided by the `https://developer.android.com/reference/kotlin/java/util/Deque` interface and its implementations, which should be used in preference to this class. For example:

```kotlin
<code>Deque&lt;Integer&gt; stack = new ArrayDeque&lt;Integer&gt;();</code>
```

## Summary

| Public constructors ||
|---|---|
| `https://developer.android.com/reference/kotlin/java/util/Stack#Stack()()` Creates an empty Stack. |

| Public methods ||
|---|---|
| open [Boolean](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html) | `https://developer.android.com/reference/kotlin/java/util/Stack#empty()()` Tests if this stack is empty. |
| open E | `https://developer.android.com/reference/kotlin/java/util/Stack#peek()()` Looks at the object at the top of this stack without removing it from the stack. |
| open E | `https://developer.android.com/reference/kotlin/java/util/Stack#pop()()` Removes the object at the top of this stack and returns that object as the value of this function. |
| open E | `https://developer.android.com/reference/kotlin/java/util/Stack#push(java.util.Stack.E)(item: E)` Pushes an item onto the top of this stack. |
| open [Int](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html) | `https://developer.android.com/reference/kotlin/java/util/Stack#search(kotlin.Any)(o: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!)` Returns the 1-based position where an object is on this stack. |

| Inherited functions ||
|---|---|
| From class `https://developer.android.com/reference/kotlin/java/util/Vector` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#add(java.util.Vector.E)(element: E)` Appends the specified element to the end of this Vector. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#add(kotlin.Int,%20java.util.Vector.E)(index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, element: E)` Inserts the specified element at the specified position in this Vector. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#addAll(kotlin.Int,%20kotlin.collections.Collection)(index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Inserts all of the elements in the specified Collection into this Vector at the specified position. Shifts the element currently at that position (if any) and any subsequent elements to the right (increases their indices). The new elements will appear in the Vector in the order that they are returned by the specified Collection's iterator. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#addAll(kotlin.collections.Collection)(elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this Vector, and this Vector is nonempty.) <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#addElement(java.util.Vector.E)(obj: E)` Adds the specified component to the end of this vector, increasing its size by one. The capacity of this vector is increased if its size becomes greater than its capacity. This method is identical in functionality to the #add(java.lang.Object) method (which is part of the `https://developer.android.com/reference/kotlin/java/util/List` interface). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#capacity()()` Returns the current capacity of this vector. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#clear()()` Removes all of the elements from this Vector. The Vector will be empty after this call returns (unless it throws an exception). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#clone()()` Returns a clone of this vector. The copy will contain a reference to a clone of the internal data array, not a reference to the original internal data array of this `Vector` object. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#contains(java.util.Vector.E)(element: E?)` Returns `true` if this vector contains the specified element. More formally, returns `true` if and only if this vector contains at least one element `e` such that `Objects.equals(o, e)`. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#containsAll(kotlin.collections.Collection)(elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Returns true if this Vector contains all of the elements in the specified Collection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#copyInto(kotlin.Array)(anArray: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!>)` Copies the components of this vector into the specified array. The item at index `k` in this vector is copied into component `k` of `anArray`. <br /> | | `E` | `https://developer.android.com/reference/kotlin/java/util/Vector#elementAt(kotlin.Int)(index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Returns the component at the specified index. This method is identical in functionality to the `https://developer.android.com/reference/kotlin/java/util/Vector#get(kotlin.Int)` method (which is part of the `https://developer.android.com/reference/kotlin/java/util/List` interface). <br /> | | `https://developer.android.com/reference/kotlin/java/util/Enumeration<E>` | `https://developer.android.com/reference/kotlin/java/util/Vector#elements()()` Returns an enumeration of the components of this vector. The returned `Enumeration` object will generate all items in this vector. The first item generated is the item at index `0`, then the item at index `1`, and so on. If the vector is structurally modified while enumerating over the elements then the results of enumerating are undefined. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#ensureCapacity(kotlin.Int)(minCapacity: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Increases the capacity of this vector, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument. If the current capacity of this vector is less than `minCapacity`, then its capacity is increased by replacing its internal data array, kept in the field `elementData`, with a larger one. The size of the new data array will be the old size plus `capacityIncrement`, unless the value of `capacityIncrement` is less than or equal to zero, in which case the new capacity will be twice the old capacity; but if this new size is still smaller than `minCapacity`, then the new capacity will be `minCapacity`. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#equals(kotlin.Any)(other: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?)` Compares the specified Object with this Vector for equality. Returns true if and only if the specified Object is also a List, both Lists have the same size, and all corresponding pairs of elements in the two Lists are *equal* . (Two elements `e1` and `e2` are *equal* if `Objects.equals(e1, e2)`.) In other words, two Lists are defined to be equal if they contain the same elements in the same order. <br /> | | `E` | `https://developer.android.com/reference/kotlin/java/util/Vector#firstElement()()` Returns the first component (the item at index `0`) of this vector. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#forEach(java.util.function.Consumer)(action: https://developer.android.com/reference/kotlin/java/util/function/Consumer<in E>)` <br /> | | `E` | `https://developer.android.com/reference/kotlin/java/util/Vector#get(kotlin.Int)(index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Returns the element at the specified position in this Vector. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#hashCode()()` Returns the hash code value for this Vector. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#indexOf(kotlin.Any,%20kotlin.Int)(o: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?, index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Returns the index of the first occurrence of the specified element in this vector, searching forwards from `index`, or returns -1 if the element is not found. More formally, returns the lowest index `i` such that `(i >= index && Objects.equals(o, get(i)))`, or -1 if there is no such index. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#indexOf(java.util.Vector.E)(element: E?)` Returns the index of the first occurrence of the specified element in this vector, or -1 if this vector does not contain the element. More formally, returns the lowest index `i` such that `Objects.equals(o, get(i))`, or -1 if there is no such index. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#insertElementAt(java.util.Vector.E,%20kotlin.Int)(obj: E, index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Inserts the specified object as a component in this vector at the specified `index`. Each component in this vector with an index greater or equal to the specified `index` is shifted upward to have an index one greater than the value it had previously. The index must be a value greater than or equal to `0` and less than or equal to the current size of the vector. (If the index is equal to the current size of the vector, the new element is appended to the Vector.) This method is identical in functionality to the `https://developer.android.com/reference/kotlin/java/util/Vector#add(kotlin.Int,%20java.util.Vector.E)` method (which is part of the `https://developer.android.com/reference/kotlin/java/util/List` interface). Note that the `add` method reverses the order of the parameters, to more closely match array usage. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#isEmpty()()` Tests if this vector has no components. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-iterator/index.html<E>` | `https://developer.android.com/reference/kotlin/java/util/Vector#iterator()()` Returns an iterator over the elements in this list in proper sequence. The returned iterator is [*fail-fast*](https://developer.android.com/reference/kotlin/java/util/Vector#fail-fast). <br /> | | `E` | `https://developer.android.com/reference/kotlin/java/util/Vector#lastElement()()` Returns the last component of the vector. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#lastIndexOf(kotlin.Any,%20kotlin.Int)(o: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?, index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Returns the index of the last occurrence of the specified element in this vector, searching backwards from `index`, or returns -1 if the element is not found. More formally, returns the highest index `i` such that `(i <= index && Objects.equals(o, get(i)))`, or -1 if there is no such index. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#lastIndexOf(java.util.Vector.E)(element: E?)` Returns the index of the last occurrence of the specified element in this vector, or -1 if this vector does not contain the element. More formally, returns the highest index `i` such that `Objects.equals(o, get(i))`, or -1 if there is no such index. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list-iterator/index.html<E>` | `https://developer.android.com/reference/kotlin/java/util/Vector#listIterator()()` Returns a list iterator over the elements in this list (in proper sequence). The returned list iterator is [*fail-fast*](https://developer.android.com/reference/kotlin/java/util/Vector#fail-fast). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list-iterator/index.html<E>` | `https://developer.android.com/reference/kotlin/java/util/Vector#listIterator(kotlin.Int)(index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. The specified index indicates the first element that would be returned by an initial call to `https://developer.android.com/reference/kotlin/java/util/ListIterator#next()`. An initial call to `https://developer.android.com/reference/kotlin/java/util/ListIterator#previous()` would return the element with the specified index minus one. The returned list iterator is [*fail-fast*](https://developer.android.com/reference/kotlin/java/util/Vector#fail-fast). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#remove(java.util.Vector.E)(element: E?)` Removes the first occurrence of the specified element in this Vector If the Vector does not contain the element, it is unchanged. More formally, removes the element with the lowest index i such that `Objects.equals(o, get(i))` (if such an element exists). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#removeAll(kotlin.collections.Collection)(elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Removes from this Vector all of its elements that are contained in the specified Collection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#removeAllElements()()` Removes all components from this vector and sets its size to zero. This method is identical in functionality to the #clear method (which is part of the `https://developer.android.com/reference/kotlin/java/util/List` interface). <br /> | | `E` | `https://developer.android.com/reference/kotlin/java/util/Vector#removeAt(kotlin.Int)(index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Removes the element at the specified position in this Vector. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the Vector. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#removeElement(kotlin.Any)(obj: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html?)` Removes the first (lowest-indexed) occurrence of the argument from this vector. If the object is found in this vector, each component in the vector with an index greater or equal to the object's index is shifted downward to have an index one smaller than the value it had previously. This method is identical in functionality to the #remove(java.lang.Object) method (which is part of the `https://developer.android.com/reference/kotlin/java/util/List` interface). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#removeElementAt(kotlin.Int)(index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Deletes the component at the specified index. Each component in this vector with an index greater or equal to the specified `index` is shifted downward to have an index one smaller than the value it had previously. The size of this vector is decreased by `1`. The index must be a value greater than or equal to `0` and less than the current size of the vector. This method is identical in functionality to the `https://developer.android.com/reference/kotlin/java/util/Vector#removeAt(kotlin.Int)` method (which is part of the `https://developer.android.com/reference/kotlin/java/util/List` interface). Note that the `remove` method returns the old value that was stored at the specified position. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#removeIf(java.util.function.Predicate)(filter: https://developer.android.com/reference/kotlin/java/util/function/Predicate<in E>)` <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#removeRange(kotlin.Int,%20kotlin.Int)(fromIndex: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, toIndex: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Removes from this list all of the elements whose index is between `fromIndex`, inclusive, and `toIndex`, exclusive. Shifts any succeeding elements to the left (reduces their index). This call shortens the list by `(toIndex - fromIndex)` elements. (If `toIndex==fromIndex`, this operation has no effect.) <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#replaceAll(java.util.function.UnaryOperator)(operator: https://developer.android.com/reference/kotlin/java/util/function/UnaryOperator<E>)` <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#retainAll(kotlin.collections.Collection)(elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Retains only the elements in this Vector that are contained in the specified Collection. In other words, removes from this Vector all of its elements that are not contained in the specified Collection. <br /> | | `E` | `https://developer.android.com/reference/kotlin/java/util/Vector#set(kotlin.Int,%20java.util.Vector.E)(index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, element: E)` Replaces the element at the specified position in this Vector with the specified element. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#setElementAt(java.util.Vector.E,%20kotlin.Int)(obj: E, index: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets the component at the specified `index` of this vector to be the specified object. The previous component at that position is discarded. The index must be a value greater than or equal to `0` and less than the current size of the vector. This method is identical in functionality to the `https://developer.android.com/reference/kotlin/java/util/Vector#set(kotlin.Int,%20java.util.Vector.E)` method (which is part of the `https://developer.android.com/reference/kotlin/java/util/List` interface). Note that the `set` method reverses the order of the parameters, to more closely match array usage. Note also that the `set` method returns the old value that was stored at the specified position. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#setSize(kotlin.Int)(newSize: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Sets the size of this vector. If the new size is greater than the current size, new `null` items are added to the end of the vector. If the new size is less than the current size, all components at index `newSize` and greater are discarded. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#sort(java.util.Comparator)(c: https://developer.android.com/reference/kotlin/java/util/Comparator<in E>?)` Sorts this list according to the order induced by the specified `https://developer.android.com/reference/kotlin/java/util/Comparator`. All elements in this list must be *mutually comparable* using the specified comparator (that is, `c.compare(e1, e2)` must not throw a `ClassCastException` for any elements `e1` and `e2` in the list). If the specified comparator is `null` then all elements in this list must implement the `https://developer.android.com/reference/kotlin/java/lang/Comparable.html#` interface and the elements' [natural ordering](https://developer.android.com/reference/kotlin/java/lang/Comparable.html#) should be used. This list must be modifiable, but need not be resizable. For apps running on and targeting Android versions greater than Nougat (API level `> 25`), `https://developer.android.com/reference/kotlin/java/util/Collections#sort(kotlin.collections.MutableList)` delegates to this method. Such apps must not call `https://developer.android.com/reference/kotlin/java/util/Collections#sort(kotlin.collections.MutableList)` from this method. Instead, prefer not overriding this method at all. If you must override it, consider this implementation: ```kotlin @Override public void sort(Comparator<? super E> c) { Object[] elements = toArray(); Arrays.sort(elements, c); ListIterator<E> iterator = (ListIterator<Object>) listIterator(); for (Object element : elements) { iterator.next(); iterator.set((E) element); } } ``` <br /> | | `https://developer.android.com/reference/kotlin/java/util/Spliterator<E>` | `https://developer.android.com/reference/kotlin/java/util/Vector#spliterator()()` Creates a *[late-binding](https://developer.android.com/reference/kotlin/java/util/Spliterator#binding)* and *fail-fast* `https://developer.android.com/reference/kotlin/java/util/Spliterator` over the elements in this list. The `Spliterator` reports `https://developer.android.com/reference/kotlin/java/util/Spliterator#SIZED:kotlin.Int`, `https://developer.android.com/reference/kotlin/java/util/Spliterator#SUBSIZED:kotlin.Int`, and `https://developer.android.com/reference/kotlin/java/util/Spliterator#ORDERED:kotlin.Int`. Overriding implementations should document the reporting of additional characteristic values. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-mutable-list/index.html<E>` | `https://developer.android.com/reference/kotlin/java/util/Vector#subList(kotlin.Int,%20kotlin.Int)(fromIndex: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html, toIndex: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html)` Returns a view of the portion of this List between fromIndex, inclusive, and toIndex, exclusive. (If fromIndex and toIndex are equal, the returned List is empty.) The returned List is backed by this List, so changes in the returned List are reflected in this List, and vice-versa. The returned List supports all of the optional List operations supported by this List. This method eliminates the need for explicit range operations (of the sort that commonly exist for arrays). Any operation that expects a List can be used as a range operation by operating on a subList view instead of a whole List. For example, the following idiom removes a range of elements from a List: ```kotlin list.subList(from, to).clear(); ``` Similar idioms may be constructed for indexOf and lastIndexOf, and all of the algorithms in the Collections class can be applied to a subList. The semantics of the List returned by this method become undefined if the backing list (i.e., this List) is *structurally modified* in any way other than via the returned List. (Structural modifications are those that change the size of the List, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results.) <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!>` | `https://developer.android.com/reference/kotlin/java/util/Vector#toArray()()` Returns an array containing all of the elements in this Vector in the correct order. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<T>` | `https://developer.android.com/reference/kotlin/java/util/Vector#toArray(kotlin.Array)(a: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<T>)` Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array. If the Vector fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this Vector. If the Vector fits in the specified array with room to spare (i.e., the array has more elements than the Vector), the element in the array immediately following the end of the Vector is set to null. (This is useful in determining the length of the Vector *only* if the caller knows that the Vector does not contain any null elements.) <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#toString()()` Returns a string representation of this Vector, containing the String representation of each element. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#trimToSize()()` Trims the capacity of this vector to be the vector's current size. If the capacity of this vector is larger than its current size, then the capacity is changed to equal the size by replacing its internal data array, kept in the field `elementData`, with a smaller one. An application can use this operation to minimize the storage of a vector. <br /> | ||
| From class `https://developer.android.com/reference/kotlin/java/util/AbstractCollection` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#addAll(kotlin.collections.Collection)(elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Adds all of the elements in the specified collection to this collection (optional operation). The behavior of this operation is undefined if the specified collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified collection is this collection, and this collection is nonempty.) If the specified collection has a defined [encounter order](https://developer.android.com/reference/kotlin/java/util/SequencedCollection#encounter), processing of its elements generally occurs in that order. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#contains(java.util.AbstractCollection.E)(element: E?)` Returns `true` if this collection contains the specified element. More formally, returns `true` if and only if this collection contains at least one element `e` such that `Objects.equals(o, e)`. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#containsAll(kotlin.collections.Collection)(elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Returns `true` if this collection contains all of the elements in the specified collection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#isEmpty()()` Returns `true` if this collection contains no elements. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#remove(java.util.AbstractCollection.E)(element: E?)` Removes a single instance of the specified element from this collection, if it is present (optional operation). More formally, removes an element `e` such that `Objects.equals(o, e)`, if this collection contains one or more such elements. Returns `true` if this collection contained the specified element (or equivalently, if this collection changed as a result of the call). <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#removeAll(kotlin.collections.Collection)(elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Removes all of this collection's elements that are also contained in the specified collection (optional operation). After this call returns, this collection will contain no elements in common with the specified collection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#retainAll(kotlin.collections.Collection)(elements: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-collection/index.html<E>)` Retains only the elements in this collection that are contained in the specified collection (optional operation). In other words, removes from this collection all of its elements that are not contained in the specified collection. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!>` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#toArray()()` Returns an array containing all of the elements in this collection. If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. The returned array's [runtime component type](https://developer.android.com/reference/kotlin/java/lang/Class.html#getComponentType()) is `Object`. The returned array will be "safe" in that no references to it are maintained by this collection. (In other words, this method must allocate a new array even if this collection is backed by an array). The caller is thus free to modify the returned array. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<T>` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#toArray(kotlin.Array)(a: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<T>)` Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. If the collection fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection. If this collection fits in the specified array with room to spare (i.e., the array has more elements than this collection), the element in the array immediately following the end of the collection is set to `null`. (This is useful in determining the length of this collection *only* if the caller knows that this collection does not contain any `null` elements.) If this collection makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#toString()()` Returns a string representation of this collection. The string representation consists of a list of the collection's elements in the order they are returned by its iterator, enclosed in square brackets (`"[]"`). Adjacent elements are separated by the characters `", "` (comma and space). Elements are converted to strings as by `https://developer.android.com/reference/kotlin/java/lang/String.html#valueOf(kotlin.Any)`. <br /> | ||

| Inherited properties ||
|---|---|
| From class `https://developer.android.com/reference/kotlin/java/util/Vector` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#capacityIncrement:kotlin.Int` The amount by which the capacity of the vector is automatically incremented when its size becomes greater than its capacity. If the capacity increment is less than or equal to zero, the capacity of the vector is doubled each time it needs to grow. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#elementCount:kotlin.Int` The number of valid components in this `Vector` object. Components `elementData[0]` through `elementData[elementCount-1]` are the actual items. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html!>` | `https://developer.android.com/reference/kotlin/java/util/Vector#elementData:kotlin.Array` The array buffer into which the components of the vector are stored. The capacity of the vector is the length of this array buffer, and is at least large enough to contain all the vector's elements. Any array elements following the last element in the Vector are null. <br /> | | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/Vector#size:kotlin.Int` Returns the number of components in this vector. <br /> | ||
| From class `https://developer.android.com/reference/kotlin/java/util/AbstractList` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractList#modCount:kotlin.Int` The number of times this list has been *structurally modified*. Structural modifications are those that change the size of the list, or otherwise perturb it in such a fashion that iterations in progress may yield incorrect results. This field is used by the iterator and list iterator implementation returned by the `iterator` and `listIterator` methods. If the value of this field changes unexpectedly, the iterator (or list iterator) will throw a `ConcurrentModificationException` in response to the `next`, `remove`, `previous`, `set` or `add` operations. This provides *fail-fast* behavior, rather than non-deterministic behavior in the face of concurrent modification during iteration. **Use of this field by subclasses is optional.** If a subclass wishes to provide fail-fast iterators (and list iterators), then it merely has to increment this field in its `add(int, E)` and `remove(int)` methods (and any other methods that it overrides that result in structural modifications to the list). A single call to `add(int, E)` or `remove(int)` must add no more than one to this field, or the iterators (and list iterators) will throw bogus `ConcurrentModificationExceptions`. If an implementation does not wish to provide fail-fast iterators, this field may be ignored. <br /> | ||
| From class `https://developer.android.com/reference/kotlin/java/util/AbstractCollection` |---|---| | `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/java/util/AbstractCollection#size:kotlin.Int` Returns the number of elements in this collection. If this collection contains more than `Integer.MAX_VALUE` elements, returns `Integer.MAX_VALUE`. <br /> | ||

## Public constructors

### Stack

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
Stack()
```

Creates an empty Stack.

## Public methods

### empty

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun empty(): Boolean
```

Tests if this stack is empty.

| Return ||
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-boolean/index.html` | `true` if and only if this stack contains no items; `false` otherwise. |

### peek

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun peek(): E
```

Looks at the object at the top of this stack without removing it from the stack.

| Return ||
|---|---|
| `E` | the object at the top of this stack (the last item of the `Vector` object). |

| Exceptions ||
|---|---|
| `java.util.EmptyStackException` | if this stack is empty. |

### pop

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun pop(): E
```

Removes the object at the top of this stack and returns that object as the value of this function.

| Return ||
|---|---|
| `E` | The object at the top of this stack (the last item of the `Vector` object). |

| Exceptions ||
|---|---|
| `java.util.EmptyStackException` | if this stack is empty. |

### push

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun push(item: E): E
```

Pushes an item onto the top of this stack. This has exactly the same effect as:

```kotlin
addElement(item)
```

<br />

| Parameters ||
|---|---|
| `item` | E: the item to be pushed onto this stack. |

| Return ||
|---|---|
| `E` | the `item` argument. |

**See Also**

- `https://developer.android.com/reference/kotlin/java/util/Vector#addElement(java.util.Vector.E)`

### search

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

```
open fun search(o: Any!): Int
```

Returns the 1-based position where an object is on this stack. If the object `o` occurs as an item in this stack, this method returns the distance from the top of the stack of the occurrence nearest the top of the stack; the topmost item on the stack is considered to be at distance `1`. The `equals` method is used to compare `o` to the items in this stack.

| Parameters ||
|---|---|
| `o` | [Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)!: the desired object. |

| Return ||
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-int/index.html` | the 1-based position from the top of the stack where the object is located; the return value `-1` indicates that the object is not on the stack. |