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


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: 

Updated on: 25-Feb-2020

253 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements