java stack push
package com.tutorialspoint;
import java.util.*;
public class StackDemo {
public static void main(String args[]) {
// creating stack
Stack st = new Stack();
// populating stack
st.push("Java");
st.push("Source");
st.push("code");
// removing top object
System.out.println("Removed object is: "+st.pop());
// elements after remove
System.out.println("Elements after remove: "+st);
}
}// Java code to illustrate push() method
import java.util.*;
public class StackDemo {
public static void main(String args[])
{
// Creating an empty Stack
Stack<Integer> STACK = new Stack<Integer>();
// Use push() to add elements into the Stack
STACK.push(10);
STACK.push(15);
STACK.push(30);
STACK.push(20);
STACK.push(5);
// Displaying the Stack
System.out.println("Initial Stack: " + STACK);
// Pushing elements into the Stack
STACK.push(1254);
STACK.push(4521);
// Displaying the final Stack
System.out.println("Final Stack: " + STACK);
}
}
Also in Java:
- java script print date in YYYY-MM-DD format
- system.in example in java
- diagonal difference hackerrank solution in java 8 using list
- iterate map in java 8 using stream
- how to import another class in java
- java download file from url to string
- java class
- how to add a number to an array in java
- loop an array of objects in java
- java catch multiple exceptions
- java http interceptor
- 2d array length in java
- convert array of int to arraylist java
- java clear bufffer to take next string inpuit
- processing pi
- java get current milliseconds
- java null pointer exception
- how to add integers in java
- java jagged array days and months
- java replaceall single character
- java \t
- java search file in folder
- java loop through object
- spigot repeating task