Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

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

514 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements