8:51 am - Sunday October 21, 2018

Vector Example program to add an element at specified index using add()

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 add() method
 */
import java.util.Vector;

class AddElementToSpecifiedIndexVector {
	public static void main(String[] args) {
		// creating Vector Object
		Vector v = new Vector();
		v.add("1");
		v.add("2");
		v.add("3");
		// add() method the element has to be inserted into the specified index
		// position
		v.add(1, "INSERTED ELEMENT");
		System.out.println("Vector contains...");
		for (int index = 0; index < v.size(); index++)
			System.out.println(v.get(index));
	}
}

OUTPUT:

D:\CandidJava\Util\Vector>javac AddElementToSpecifiedIndexVector.java

Note: AddElementToSpecifiedIndexVector.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\Vector>java AddElementToSpecifiedIndexVector

Vector contains…

1

INSERTED ELEMENT

2

3

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply