12:07 am - Monday June 25, 2018

Stack Example Program for addElement(E obj)

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 addElement(E obj)
*/

import java.io.*;
import java.util.*;
public class StackElement
{
public static void main(String args[])
{
Stack s=new Stack();    // to create object for Stack class
s.add("blue");    //to add an element in stack
s.add("green");    //to add an element in stack
s.add("yellow");     //to add an element in stack
System.out.println(s);
s.addElement("red"); // Adds the specified component to the end of this stack, increasing its size by one
System.out.println(s);
}
}

OUTPUT:
[blue, green, yellow]
[blue, green, yellow, red]

BACK

Filed in: Z-A All Java Codes

Comments are closed.