12:49 am - Monday August 21, 2017

Stack Example Program for clone()

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
*@description:Stack example program for clone()

*/

import java.util.Stack;

public class StackClone {
public static void main(String[] args) {

Stack s1 = new Stack(); // creating first stack

for (int i = 1; i <= 10; i++) {

s1.push(i);

}

System.out.println("First Stack peek value : " + s1.peek());

Stack s2 = (Stack) s1.clone(); // creating the clone of first stack

System.out.println("Second Stack peek value : " + s2.peek());

}
}


OUTPUT:
First Stack peek value : 10
Second Stack peek value : 10

Filed in: Z-A All Java Codes

Comments are closed.