Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java push() Method

import java.util.Stack;

class Main {
    public static void main(String[] args) {
        Stack<String> animals= new Stack<>();

        // Add elements to Stack
        animals.push("Dog");
        animals.push("Horse");
        animals.push("Cat");

        System.out.println("Stack: " + animals);
    }
}
Comment

push function in java

// Java Code to illustrate push() Method
 
import java.util.*;
 
// Main class
public class StackDemo {
 
    // Main driver method
    public static void main(String args[])
    {
        // Creating an empty Stack
        Stack& lt;
        String& gt;
        STACK = new Stack& lt;
        String& gt;
        ();
 
        // Adding elements into the stack
        // using push() method
        STACK.push(" Welcome & quot;);
        STACK.push(" To & quot;);
        STACK.push(" Geeks & quot;);
        STACK.push(" For & quot;);
        STACK.push(" Geeks & quot;);
 
        // Displaying the Stack
        System.out.println(" Initial Stack
                           : "
                           + STACK);
 
        // Pushing elements into the stack
        STACK.push(" Hello & quot;);
        STACK.push(" World & quot;);
 
        // Displaying the final Stack
        System.out.println(" Final Stack
                           : "
                           + STACK);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: simple java code 
Java :: glide dependency 
Java :: java dimension 
Java :: java string array to arraylist 
Java :: java get number of months between two dates 
Java :: how to find the prime numbers in java 
Java :: string length in android studio java 
Java :: math.absolute java 
Java :: java convert float to double 
Java :: java final meaning 
Java :: java substring after last char 
Java :: make textview invisible android 
Java :: hollow pyramid star pattern in java 
Java :: Binary tree using linked list in Java 
Java :: java random double between 0 and 1 
Java :: gat environment variables java 
Java :: for java 
Java :: if driver.find_element_by_xpath selnium java is displayed 
Java :: android java back button closeapp 
Java :: register watch service java 
Java :: how to get internet speed in android programmatically 
Java :: java random number generator in range 
Java :: how to turna date into a LocalDateTime java 
Java :: remove duplicate from string 
Java :: initialize an array in java 
Java :: button onclick java 
Java :: static import java 
Java :: java swing get frame size 
Java :: declare a hashmap in java 
Java :: how to find sum of the digit of the numbers in java 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =