Monday, 25 May 2015

How to add all elements of a list to Vector

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class AddAllElement {
    public static void main(String[] args) {
        Vector<String> vector = new Vector<String>();
        //add element in vector
        // print vector
        System.out.println("Vector = "+vector);
        List<String> list =  new ArrayList<>();
        System.out.println("list = "+list);
         * Appends all of the elements in the specified
         * Collection to the end of this Vector, in the
         * order that they are returned by the specified
         *  Collection's Iterator.

       System.out.println("vector after add list ="+vector);



Vector = [cricket, hockey, football, tennish]

list = [java, c++, php]

vector after add list =[cricket, hockey, football, tennish, java, c++, php]

No comments:

Post a Comment