Home TechnologyProgrammingJava Subscribe to RSS
 

How To Define Stack Data Type In Java?

Answer Question

1 Answer - Sort by: Date | Rating


    You can user Stack Class in java.util


    import java.util.Stack; 

    public class StackExample {
      public static void main(String args[]) {
        Stack s = new Stack();
        s.push("Java");
        s.push("Source");
        s.push("and");

        System.out.println("Next: " + s.peek());
        s.push("Support");
        System.out.println(s.pop());
        s.push(".");
        int count = s.search("Java");
        while (count != -1 && count > 1) {
          s.pop();
          count--;
        }
        System.out.println(s.pop());
        System.out.println(s.empty());
      }
    }

    Hope it Helps, 

    any further assistance msg me

    1 1

    Rinav 

    answered 10 months ago

      Answer Question - Answers are editable for 5 min.

      If you do not Sign-in or Register your answers will be anonymous,

      your answers may also be checked before going online.

      More

         
         

        Ask a Question via Twitter

        Send a question to @askblurtit and we will publish it online and send you a reply everytime you receive an answer.

        Blurtit Store

        Get T-shirts, hoodies, caps and more at the Blurtit store

        Blurtit International