/** * @author lautturi.com * Java example: find element in java stack */ import java.util.*; public class Lautturi { public static void main(String[] args){ Stack<String> stack= new Stack<>(); // Add elements to Stack stack.push("lautturi"); stack.push("java"); stack.push("python"); stack.push("hello"); stack.push("js"); stack.push("php"); stack.push("perl"); System.out.println("Stack: " + stack); // Search an element int position = stack.search("hello"); System.out.println("Position of hello: " + position); } }Souw:ecrww.lautturi.com
output:
Stack: [lautturi, java, python, hello, js, php, perl] Position of hello: 4