- Typparameter:
T- the type of elements maintained by this Collection
- Alle bekannten Implementierungsklassen:
CopyOnWriteObjectArrayList,ObjectArrayList,ObjectLinkedList
public interface Stack<T>
The Stack Interface represents the Last-In-First-Out layout (LIFO).
It provides a simple
push(Object), pop() function,
with a fast clear() function.
The peek(int) function allows to view the contents of the stack (top to bottom).-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoidclear()Clears the stackdefault booleanisEmpty()peek(int index) Provides the Selected Object from the stack.pop()Removes the Object on top of the stack.voidInserts a given Object on top of the stackdefault voidpushTop()Helper function that pushes the top element on top of the stack again.intsize()Provides the amount of elements currently in the stackdefault <E> E[]toArray()A method to drop the contents of the Queue without clearing the queue<E> E[]toArray(E[] array) A method to drop the contents of the Stack without clearing the stackdefault <E> E[]toArray(IntFunction<E[]> action) A Helper function that simplifies the process of creating a new Array.default Ttop()Provides the Object on top of the stack
-
Methodendetails
-
push
Inserts a given Object on top of the stack- Parameter:
e- the Object to insert
-
pushTop
default void pushTop()Helper function that pushes the top element on top of the stack again.- Löst aus:
NoSuchElementException- if the stack is empty
-
pop
T pop()Removes the Object on top of the stack.- Gibt zurück:
- the element that is on top of the stack
- Löst aus:
ArrayIndexOutOfBoundsException- if the stack is empty
-
size
int size()Provides the amount of elements currently in the stack- Gibt zurück:
- amount of elements in the list
-
isEmpty
default boolean isEmpty()- Gibt zurück:
- if the stack is empty
-
clear
void clear()Clears the stack -
top
Provides the Object on top of the stack- Gibt zurück:
- the element that is on top of the stack
- Löst aus:
ArrayIndexOutOfBoundsException- if the stack is empty
-
peek
Provides the Selected Object from the stack. Top to bottom- Parameter:
index- of the element that should be provided- Gibt zurück:
- the element that was requested
- Löst aus:
ArrayIndexOutOfBoundsException- if the index is out of bounds
-
toArray
default <E> E[] toArray()A method to drop the contents of the Queue without clearing the queue- Typparameter:
E- the keyType of elements maintained by this Collection- Gibt zurück:
- the contents of the queue into a seperate array.
-
toArray
<E> E[] toArray(E[] array) A method to drop the contents of the Stack without clearing the stack- Typparameter:
E- the keyType of elements maintained by this Collection- Parameter:
array- where the elements should be inserted to. If it does not fit then it creates a new appropriately created array- Gibt zurück:
- the contents of the stack into a separate array.
- Note:
- if the Type is generic then a Object Array is created instead of a Type Array
-
toArray
A Helper function that simplifies the process of creating a new Array.- Typparameter:
E- the returning arrayType- Parameter:
action- the array creation function- Gibt zurück:
- an array containing all of the elements in this collection
- Siehe auch:
-