search element in java stack

search element in java stack
/**
 * @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);
	}
}
Sou‮w:ecr‬ww.lautturi.com

output:

Stack: [lautturi, java, python, hello, js, php, perl]
Position of hello: 4
Created Time:2017-09-29 14:58:46  Author:lautturi