10:32 pm - Monday May 21, 2018

Vector Example program to append all elements of other Collection using addAll()

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

class AppendAllElementsOfOtherCollectionToVector {
	public static void main(String[] args) {
		// creating Vector Object
		Vector v = new Vector();
		v.add("1");
		v.add("2");
		v.add("3");
		// creating ArrayList Object
		ArrayList arrayList = new ArrayList();
		arrayList.add("4");
		arrayList.add("5");
		// apped all the elements of ArrayList elements to the elements of
		// Vector
		v.addAll(arrayList);
		System.out
				.println("After appending all elements of ArrayList,Vector contains..");
		for (int i = 0; i < v.size(); i++)
			System.out.println(v.get(i));
	}
}

OUTPUT:

D:\CandidJava\Util\Vector>javac “AppendAllElementsOfOtherCollectionToVector .java”

Note: AppendAllElementsOfOtherCollectionToVector .java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\Vector>java “AppendAllElementsOfOtherCollectionToVector”

After appending all elements of ArrayList,Vector contains..

1

2

3

4

5

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply