What does the method search(Object o) do in java?

Java 8Object Oriented ProgrammingProgramming

The search(Object o) method is used to return the 1-based position where an object is on this stack.

Example

import java.util.*;
public class StackDemo {
   public static void main(String args[])  {
     
      Stack st = new Stack();
      st.push("Java");
      st.push("Source");
      st.push("code");
      System.out.println("Searching 'code' in stack: "+st.search("code"));
   }
}

Output

Searching 'code' in stack: 
raja
Published on 08-Feb-2018 08:51:27
Advertisements