ArrayList and stack overview

  • Eclipse: Oxygen
  • Java: 1.8


In this tutorial, we will discuss ArrayList and stack. The ArrayList shown earlier has some disadvantages such as very slow deletion or addition.

ArrayList is a very important data structure useful in handling the dynamic behavior of elements. However, it can be slower than standard arrays, but it can be useful in programs where a lot of manipulation is needed.


  • Fast
  • Easy to access any element from any location


  • Operations are slow
  • Tends to use more memory while operating


We see the stack data structure here. The properties of stack data structure are shown here and there some of the operations that include the search, insertion, deletion and the front element in the stack is shown here.

Java Stack is a LIFO (Last in first out) object. Extends the Vector class but supports only five operations. The Java stack class only has one constructor that is empty or the default constructor. Then, when we create a Stack, initially it does not contain elements that mean that the Stack is empty.

Let’s understand the method by the following table.

   Modifier and Type                                   Method and Description
boolean Empty( ) Tests if this stack is empty.
E Peek( )Looks at the object at the top of this stack without removing it from the stack
E Pop( ) Removes the object at the top of this stack and returns that object as the value of this function.
E Push( E item) Pushes an item onto the top of this stack.
int search(object o) Returns the 1 – based position where an object is on this stack.

Contributed by: Poonam Tomar

Full stack Java Developer

   Buy me a coffee!



Download file

Leave a Reply

Notify of
Close Menu