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

Java 8Object Oriented ProgrammingProgramming

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]
raja
Published on 08-Feb-2018 08:56:08
Advertisements