Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Java collection Stack example

Have Programming Question? Ask it here!
 
 
 


Naulej kumar
Java collection Stack example
1 Answer(s)      2 years and a month ago
Posted in : Java Beginners


How to use Stack class in java collection?


Advertisement
View Answers

June 22, 2012 at 3:00 PM


The Stack class uses the First In Last Out(FILO) mechanism. Here is an example of Stack class.

import java.util.Stack;

public class StackExample {
    public static void main(String [] args){
        Stack stack = new Stack();
        stack.push("Angelina Jolie");
        stack.push("Jennifer Aniston");
        stack.push("Scarlett Johansson");
        stack.push("Reese Witherspoon");
        stack.push("Megan Fox");
        stack.push("Nicole Kidman");
        System.out.println("The elements in the Stack :- " + stack);
        System.out.println("The element at the top :- " +stack.peek());
        System.out.println("The element poped out of the stack :- " + stack.pop());
        System.out.println("The element in a stack after pop out an element- : " +stack);
        System.out.println("The result of searching :- " +stack.search(" r u"));
    }


}

Output:-

The elements in the Stack :- [Angelina Jolie, Jennifer Aniston, Scarlett Johansson, Reese Witherspoon, Megan Fox, Nicole Kidman]
The element at the top :- Nicole Kidman
The element poped out of the stack :- Nicole Kidman
The element in a stack after pop out an element- : [Angelina Jolie, Jennifer Aniston, Scarlett Johansson, Reese Witherspoon, Megan Fox]
The result of searching :- -1

Description:- The above example demonstrates you the Stack class in java collection. We are using three methods of Stack. push(object items): The push method add an items to the top of the Stack. peek(): The peek() method returns the element at the top of the Stack, and pop(): The pop() method remove the element at the top of the Stack and returns the element.



Related Tutorials/Questions & Answers:
Java collection Stack example
Java collection Stack example  How to use Stack class in java collection?   The Stack class uses the First In Last Out(FILO) mechanism... :- -1 Description:- The above example demonstrates you the Stack class in java
Collection : Stack Example
Collection : Stack Example In this tutorial we will describe implementation of stack with example. Stack : Stack is based on concept of LIFO(Last In First... if stack is empty. Some other methods - empty(), peek(), search(Object o) Example
Advertisements
Java Stack Example
the stack collection in the Java programming. In this example you will see how...Java Stack Example In this section we will read about how you can provide... Collection. Stack may have the two states while pushing and popping is occurred
Java Stack Example
Java Stack Example In this section you will learn about Stack class  in java, how to use Stack in java. Before going into details we should know what... the item in the stack and how far it is from top of stack Example : A Java code
Java collection Queue Example
Java collection Queue Example  How can we use Queue in java collection?   import java.util.LinkedList; import java.util.Queue; public... LinkedList(); queue.add("Java"); queue.add("DotNet
Java Collection iterator with example
. Example of Java Collection Iterator import java.util.ArrayList; import... The Java Collection Iterator is present at the highest level interface in the Collection framework. Iterator interface has methods for traversing
Example of Java Stack Program
Example of Java Stack Program     ... it. Here in the example describes the methods to prepare an example of Java stack... of this example is given below: The contents of Stack is[10, a] The size of an Stack
stack in java/
stack in java/  java code for stack push pop and display operation? thanks
stack and queue - Java Beginners
stack and queue  write two different program in java 1.) stack 2...://www.roseindia.net/java/example/java/util/StackImplement.shtml http://www.roseindia.net/java/example/java/util/QueueImplement.shtml Hope
java technologies stack
java technologies stack  java technologies stack
stack - Java Beginners
on Stack visit to : Thanks   http://www.roseindia.net/java/example/java/util/ Thanks  I think there is bit wrong in the above answer... that inputs a line of text and uses a stack object to print the words of the line
Implementing a Stack in Java
Implementing a Stack in Java     ... in Java. A Stack is like a bucket in which you can put elements one-by-one... entered element. Stack is a collection of data and follows the LIFO (Last
Java Stack - Java Beginners
Java Stack  Can you give me a code using Java String STACK using the parenthesis symbol ( ) the user will be the one to input parenthesis......) if Open parenthesis push it to stack otherwise Pop the stack Thank you
Stack
Stack  How to implement a stack using classes in java?   Here is an example that implements a Stack class based on arrays. public class Stack { private int top; private int[] storage; Stack(int
Java stack help
Java stack help  How would I use stacks in java to do a calculation like: 4*((3+3)/(5-3
Java Collection
Java Collection  What is the Collection interface
Generic Java Stack
Generic Java Stack  Hi here the question the interviewer asked me- package jp.co.worksap.intern; /** *The Stack class represents a last-in-first-out(LIFO) stack of objects *And this class can look at the object
Java collection
Java collection  What are differences between Enumeration, ArrayList, Hashtable and Collections and Collection
ADT stack - Java Beginners
ADT stack  Design a Java interface for ADT Stack. Develop two....  Hi Friend, Try the following codes: ADT Stack: import...("Stack is empty"); return; } else { String str = " "; for (int i = 0; i <= top
java using Stack - Java Beginners
java using Stack  How convert decimal to binary using stack in java
Java Collection : NavigableSet Example
Java Collection : NavigableSet Example In this tutorial we are describing NavigableSet of collection Framework NavigableSet : NavigableSet interface..., boolean inclusive). Example : Here is an example of NavigableSet . package
ADT stack - Java Beginners
]. 2)Design a Java interface for ADT Stack. Develop two different classes...ADT stack  I want a algorithm for the below programs.... 1)Implement Lisp-like list in Java. Write basic operations such as 'car', 'cdr', and 'cons
Collection Iterate Example
Collection Iterate Example     ... of interface Iterator in Java. The description of the code is given below... the hasNext() method through the following java program. True is return
Collection : ArrayList Example
This tutorial contains description of Collection ArrayList with example
Collection : LinkedList Example
This tutorial contains description of Collection LinkedList with example
Collection in java
Collection in java  What are the meaning of the letters E,T,K and V that come in the collection concept
java using Stack - Java Beginners
java using Stack  How convert decimal to binary using stack in java? whats the java program or code to that. Thank you rose india and java... the number: "); int num = input.nextInt(); Stack stack = new Stack
Java Stack
Java Stack       The Stack class works on the principle last-in-first-out (LIFO) stack of objects... java stack click on the link: http:/www.roseindia.net/java/beginners/stack
Stack Overflow - Java Tutorials
Stack Overflow in Java A stack is the part of the memory. The local automatic variable is created on this stack and method arguments are passed. When... on due to which stack's limit exceeds. For example, take a look at given
Java Collection : LinkedHashSet Example
Java Collection : LinkedHashSet Example This tutorial contains description of LinkedHashSet with example. LinkedHashSet : LinkedHashSet class is defined... of HashSet. Example : package collection; import java.util.LinkedHashSet; class
Java Collection : TreeSet Example
Java Collection : TreeSet Example This tutorial contains description of  TreeSet with example. TreeSet  : TreeSet class is defined in java.util... constructor - TreeSet(), TreeSet(Collection c), TreeSet(Comparator c
calculator in java with stack
calculator in java with stack  i want calcultor with interface in java and in interface there is button called postfix ,,, when the user enter opertions and numbers first check if is vaild or not then convert to postfix
Java collection
Java collection  What is relation between map and set
Java Collection
Java Collection  What are Vector, Hashtable, LinkedList and Enumeration
Java collection
Java collection  What are differences between Enumeration, ArrayList, Hashtable and Collections
java collection
java collection  how do I use a treeset to print unique words
Collection : ArrayList Example
Collection : ArrayList Example This tutorial contains description of Collection ArrayList with example. ArrayList : For ArrayList<E> import... of elements to add. For such condition, the Collection Framework provides
Java Stack ADT
Java Stack ADT You all are familiar with the data structure 'Stack'. The Stack ADT is same as Stack. It is a LIFO data structure where insertions and deletions always occur at the same end. This end is called the top of the stack
Java garbage collection
Java garbage collection  What is Garbage Collection and how to call it explicitly
Java String using STACK - Java Beginners
Java String using STACK  Can you give me a code using Java String STACK using the parenthesis symbol ( ) it tells its Valid or Invalid it tells it excess parenthesis if Open parenthesis push it to stack otherwise Pop
Java Collection API - Java Tutorials
Java Collection API Collection was added to Java with J2SE 1.2 release. Collection framework is provided in 'java.util.package'. All collections.... Example : In the below example, the method "add" of Collection
Collection classes in java
is the reason using java collection classes saved/stored the data/content.I don't understand, what is the idea using java collection classes in project. Or the data is stored in both database and java collection classes
Collection classes in java
is the reason using java collection classes saved/stored the data/content.I don't understand, what is the idea using java collection classes in project. Or the data is stored in both database and java collection classes
Java collection-LinkedList
Java collection-LinkedList  How to use java collection-linked list ?   Example: import java.util.Iterator; import java.util.LinkedList; import java.util.List; public class LinkedListExample{ public static void
Java collection -Hashtable
Java collection -Hashtable   What is Hashtable in java collection?   Java collection -Hashtable;- The hashtable is used to store value...:- The above example demonstrates you the Map interface. Since Map is an interface, you
how can create album in java by using Stack ....
how can create album in java by using Stack ....  hi all , if i press push button put the image to the stack , and when i press pop button remove the image ..??? please help me please
garbage collection - Java Beginners
. For read more information : http://www.roseindia.net/java/example/java/io... of memory.It identifies the objects that are no longer used by a program. A Java object is subject to garbage collection when it becomes unreachable to the program
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Use a tree stack to sort number in java?
Use a tree stack to sort number in java?  The Question is : Three stacks can be used to sort a list of numbers. Assuming stack in holds the input list of numbers, stack out is to hold the output list after sorting the numbers
Advertisements
 

 

 

DMCA.com