3:44 pm - Sunday December 11, 2208

Stack Example Program for elementAt(int index)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and use of elementAt() .
*/
import java.io.*;
import java.util.*;
public class StackElementAt
{
public static void main(String arg[])throws Exception
{
Stack s=new Stack();//to create object for Stack class
s.add("apple");//to add an element in Stack
s.add("ball");//to add an element in Stack
s.add("cat");//to add an element in Stack
s.add("dog");//to add an element in Stack
s.add("egg");//to add an element in Stack
s.add("fox");//to add an element in Stack
s.add("gun");//to add an element in Stack
System.out.println(s);
System.out.println("Element at second place is "+s.elementAt(1)); // Returns the element at the specified index
System.out.println("Element at fifth place is "+s.elementAt(4)); // Returns the element at the specified index
}
}

OUTPUT:
[apple, ball, cat, dog, egg, fox, gun]
Element at second place is ball
Element at fifth place is egg

BACK

Filed in: Z-A All Java Codes

Comments are closed.