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]
Comments
Post a Comment