package com.javaguides.corejava.api.util;
import java.util.Stack;
/**
* Class demonstrates the usage of Stack class methods with examples
*
* @author Ramesh Fadatare
*
*/
public class ArrayToStackExample {
public static void main(String[] args) {
convertArrayToStack();
}
private static void convertArrayToStack() {
String[] strArr = {
"Java",
"JEE",
"C",
"C++",
"Spring",
"Hibernate"
};
Stack < String > stack = new Stack < > ();
for (String string: strArr) {
stack.push(string);
}
System.out.println("Non-Empty stack : " + stack);
}
}
Output:
Non-Empty stack : [Java, JEE, C, C++, Spring, Hibernate]
Reference
https://www.javaguides.net/2018/12/java-stack-class-methods-with-examples.htmlFree Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course