Vector class addAll(Collection extends E> c)method example
Appends all of the elements in the specified Collection to the end of this Vector
Vector class addAll(Collection c)method example.This example shows you how to use addAll(Collection c)method.This method Appends all of the elements in the specified Collection to the end of this Vector
Here is the code:-
/*
* @Program that Appends all of the elements in the specified Collection to the
end of this Vector
* AddAll.java
* Author:-RoseIndia Team
* Date:-24-May-2008
*/
import java.util.*;
public class AddAll {
public static void main(String[] args) {
//Constructs a LinkedList
LinkedList l=new LinkedList();
l.add("girish");
l.add("Komal");
l.add("Janoti");
//Creating a Vector containing the same elements as the LinkedList.
Vector V=new Vector();
System.out.println("Vector before adding Elements is :"+V);
//Appends all of the elements in the specified Collection to the end of this
//Vector
V.addAll(l);
//Constructs a Enumeration Interface
Enumeration e=V.elements();
System.out.print("Vector after adding all the element of linkedlist is :");
while (e.hasMoreElements())
{
System.out.print(e.nextElement()+"\t");
}
}
} |
Output of the program:-
Vector before adding Elements is :[]
Vector after adding all the element of linkedlist is :girish Komal Janoti |
|