Stack:[LAST IN FIRST OUT]
import java.util.Stack;
class StackExamp
{
public static void main(String[] args)
{Stack s=new Stack();
s.push("a");
s.push("b");
s.push("c");
s.push("d");
s.push("e");
System.out.println(s);
s.pop();
System.out.println(s);
System.out.println(s.peek());
System.out.println(s.size());
System.out.println(s.search("b"));// returns the position of b i.e.3
System.out.println(s.search("z"));//-1
ArrayList al=new ArrayList(s);// convertion object stack to arraylist
System.out.println(al);
}
}
OUTPUT:
D:\anvesh_java>java StackExamp
[a, b, c, d, e]
[a, b, c, d]
d
4
3
-1
import java.util.Stack;
class StackExamp
{
public static void main(String[] args)
{Stack s=new Stack();
s.push("a");
s.push("b");
s.push("c");
s.push("d");
s.push("e");
System.out.println(s);
s.pop();
System.out.println(s);
System.out.println(s.peek());
System.out.println(s.size());
System.out.println(s.search("b"));// returns the position of b i.e.3
System.out.println(s.search("z"));//-1
ArrayList al=new ArrayList(s);// convertion object stack to arraylist
System.out.println(al);
}
}
OUTPUT:
D:\anvesh_java>java StackExamp
[a, b, c, d, e]
[a, b, c, d]
d
4
3
-1
No comments:
Post a Comment