4:29 pm - Saturday September 23, 2017

Vector Example Program for addAll(int index, Collection c)

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
/*Program Name: Vector Example Program for addAll(int index, Collection c)*/
/**
 *@Author: Candidjava.com
 *@Description:Vector Example Program for addAll(int index, Collection c)
 Method is used to Inserts all of the elements in the specified Collection into this Vector at the
 specified position.
 */

import java.util.Vector;

public class CollectionVector1 {
	public static void main(String args[]) {
		Vector<String> v1 = new Vector<String>(3); // creating vector objects.
		Vector<String> v2 = new Vector<String>(3);
		v1.add("1"); // initialize v1 and adding elemnts.
		v1.add("7");
		v1.add("2");
		v2.add("6"); // initialize v2 and adding elements.
		v2.add("5");
		v2.add("4");
		v2.addAll(1, v1); // adding all the elements from v1 to v2 starting at
							// index 1.
		System.out.println("The elements are:");
		for (String s1 : v2)
			System.out.println("Element is:" + s1); // printing the result.

	}
}

Output:

The elements are:
Element is:6
Element is:1
Element is:7
Element is:2
Element is:5
Element is:4

Filed in: Z-A All Java Codes

Comments are closed.