Java List add all element from a collection

Description

Java List add all element from a collection

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

public class Main {
  public static void main(String[] args) {
    List<String> list = new ArrayList<String>();
    list.add("CSS");
    list.add("HTML");
    list.add("Java");

    Vector<String> v = new Vector<String>();
    v.add("sql");
    v.add("c++");

    // append all elements of Vector to ArrayList
    list.addAll(v);//from   www.  j  a v a 2  s.c o  m

    System.out.println(list);

  }

}



PreviousNext

Related