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: 2020-02-25T09:59:50+05:30

406 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements