What are the advantages of the javautilStack implementation

What are the advantages of the java.util.Stack implementation of a stack? List the five methods in the Stack class and describe their functions.

Solution

Advantage of java.util.Stack implementation of a stack :

- It is a generic implementation, so you can create stack of any data type

- All the exceptional cases are well handled.

- many methods related to Stack are available

public E push(E item)
Pushes an item onto the top of this stack. This has exactly the same effect as:
addElement(item)

public E pop()
Removes the object at the top of this stack and returns that object as the value of this function.

public E peek()
Looks at the object at the top of this stack without removing it from the stack.

public boolean empty()
Tests if this stack is empty.

public int search(Object o)
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.

What are the advantages of the java.util.Stack implementation of a stack? List the five methods in the Stack class and describe their functions.SolutionAdvantag

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site