0% found this document useful (0 votes)
6 views2 pages

Stack Methods Overview

The document provides a comprehensive overview of various stack methods and their descriptions, including operations like push, pop, peek, and search. It also details methods for manipulating collections, such as add, remove, and clear, along with utility functions like size and isEmpty. Examples of each method are provided for clarity.

Uploaded by

Chirag Saraf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Stack Methods Overview

The document provides a comprehensive overview of various stack methods and their descriptions, including operations like push, pop, peek, and search. It also details methods for manipulating collections, such as add, remove, and clear, along with utility functions like size and isEmpty. Examples of each method are provided for clarity.

Uploaded by

Chirag Saraf
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Method Description Example

push(E item) Pushes an item onto the top of the stack [Link]("A");

pop() Removes and returns the top element [Link]();

peek() Looks at the top element without removing it [Link]();

empty() Checks if the stack is empty [Link]();

search(Object o) Returns 1-based position from the top, or -1 if not found [Link]("A");

add(E e) Adds element (from Vector) [Link]("B");

add(int index, E e) Inserts element at position [Link](1, "C");

addAll(Collection c) Adds all elements from another collection [Link](list);

clear() Removes all elements [Link]();

contains(Object o) Checks if element exists [Link]("A");

get(int index) Returns element at index [Link](0);

set(int index, E e) Replaces element at index [Link](1, "X");

remove(int index) Removes element at index [Link](2);

remove(Object o) Removes first occurrence [Link]("A");

size() Returns number of elements [Link]();

isEmpty() Checks if empty [Link]();

indexOf(Object o) First index of element [Link]("A");

lastIndexOf(Object o) Last index of element [Link]("A");

toArray() Converts to Object[] Object[] arr = [Link]();

toArray(T[] a) Converts to typed array String[] arr = [Link](new String[0]);

iterator() Returns Iterator Iterator it = [Link]();

listIterator() Returns ListIterator ListIterator it = [Link]();

forEach(Consumer action) Runs action for each element [Link]([Link]::println);


removeIf(Predicate filter) Removes elements by condition [Link](x -> [Link]("A"));

replaceAll(UnaryOperator op) Replaces all elements [Link](String::toUpperCase);

sort(Comparator c) Sorts stack elements [Link](null);

spliterator() Creates Spliterator [Link]();

stream() Returns sequential stream [Link]();

parallelStream() Returns parallel stream [Link]();

You might also like