/** * @author lautturi.com * Java example: */ import java.util.*; public class Lautturi { public static void main(String[] args) { // Create a string stack Stack<String> fruits= new Stack<>(); // Add elements to Stack fruits.push("Apple"); fruits.push("Banana"); fruits.push("Mango"); fruits.push("Orange"); System.out.println("Stack: " + fruits); } }
output:
Stack: [Apple, Banana, Mango, Orange]