4:57 am - Wednesday September 26, 2018

ArrayList Example Program for addAll(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
/**
@Author:candidjava.com
@Description:Adding other collection elements to ArrayList
 */
import java.util.ArrayList;
import java.util.Vector;

public class ArrayListAddAll {
	public static void main(String args[]) {
		ArrayList al = new ArrayList(); // creating object variable for
										// arraylist
		al.add("2"); // adding elements to arraylist
		al.add("4");
		Vector v = new Vector(); // creating object for vector
		v.add("6"); // adding elements to vector
		v.add("8");
		al.addAll(v); // adding all the vector ellement to the arraylist
		System.out.println("after adding all elements to the ArratList:");
		for (int i = 0; i < al.size(); i++) // iterate throw the arraylist
											// element and display those
											// elements
		{
			System.out.println(al.get(i));
		}
	}
}

output:
after adding all elements to the ArratList:
2
4
6
8

Filed in: Z-A All Java Codes

Comments are closed.