12:12 am - Monday June 25, 2018

Stack Example Program for set(int index,E element)

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
set(int index, E element). This function used to replace specified element with given index position in the stack
*/
import java.io.*;
import java.util.*;
 public class StackSet
{
public static void main(String arg[])throws Exception
{
Stack s=new Stack();//to create object for Stack class
s.add("ab");//to add an element in Stack
s.add("bc");//to add an element in Stack
s.add("cd");//to add an element in Stack
s.add("x");//to add an element in Stack
System.out.println("before replace:"+s);
s.set(3,"de");//to replace specified element with given index position in the stack
System.out.println("after replace:"+s);
}
}

OUTPUT:
before replace:[ab, bc, cd, x]
after replace:[ ab, bc, cd, de]

BACK

Filed in: Z-A All Java Codes

Comments are closed.