3:40 am - Monday June 25, 2018

Stack Example Program for insertElementAt(E obj, 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 insertElementAt().
 */
import java.io.*;
import java.util.*;

public class StackInsert {
	public static void main(String arg[]) throws Exception {
		Stack s = new Stack();// to create object for Stack class
		s.add("a");// to add an element in Stack
		s.add("b");// to add an element in Stack
		s.add("c");// to add an element in Stack
		s.add("d");// to add an element in Stack
		s.add("e");// to add an element in Stack
		s.add("f");// to add an element in Stack
		s.add("g");// to add an element in Stack
		s.insertElementAt("h", 6); // Inserts the specified object as a
									// component in the stack at the specified
									// index
		System.out.println(s);
	}
}

OUTPUT:
[a, b, c, d, e, f, g]
After inserting
[a, b, c, d, e, f, h, g]

Filed in: Z-A All Java Codes

Comments are closed.