Syntax error What does the method push(Object item) do in java?

What does the method push(Object item) do in java?



The push(Object item) method is used to Pushes an item onto the top of this stack.

Example

import java.util.*;
public class StackDemo {
   public static void main(String args[]) {

      Stack st = new Stack();
      st.push("Java");
      st.push("Source");
      st.push("code");
      System.out.println("Elements in the stack: "+st);
   }
}

Output

Elements in the stack: [Java, Source, code]
Updated on: 2020-02-25T10:04:00+05:30

560 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements