Wednesday, December 23, 2015

Stack in java:

Stack in java:

package javaapplication27;

import java.util.Stack;


public class TestStack {
   
    public static void main(String[] args) {
        Stack obj= new Stack();
        Stack obj1= new Stack();
       
        //push some number into the stack
       
        for(int i=0;i<10;i++)
            obj.push(i);
        for(int i=0;i<20;i++)
            obj1.push(i);
       
       
        //pop those numbers off the stack
       
        System.out.println("Stack in obj");
        for(int i=0;i<10;i++)
            System.out.println(obj.pop());
       
       
        System.out.println("Stack in obj1");
        for(int i=0;i<10;i++)
            System.out.println(obj1.pop());
           
    }
   
}
OUTPUT:

Stack in obj
9
8
7
6
5
4
3
2
1
0
Stack in obj1
19
18
17
16
15
14
13
12
11
10


Related Posts:

  • equals() Versus ==equals() Versus == We should be clear that equals() method and == operator perform two different operations.The equals() method compares the characte… Read More
  • String Concatenation:String Con:catenation Here is a small java program to demonstrate String Concatenation: package stringdemo; public class StringConcat {   &nbs… Read More
  • equals() and equalsIgnoreCase()String Comparision: The String class includes many methods that compares Strings or Substrings within strings. equals() and equalsIgnoreCase() pac… Read More
  • String Concatenation with other data typeString Concatenation with other data type: package stringdemo; public class StringS {     public static void main(String[] args) {  … Read More
  • concat() and trim() methodconcat() You can concat two String using concat() as shown below: package stringdemo; public class Concat {     public static void main… Read More

0 comments:

Post a Comment