Java Collections add array to Collection

Description

Java Collections add array to Collection

import java.util.ArrayList;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    String[] langs = { "CSS", "SQL", "HTML", "C++" };
    ArrayList<String> list2 = new ArrayList<>();

    list2.add("Java");
    list2.add("Javascript");
    list2.add("C");

    System.out.println(list2);//from  w  w  w . ja  va 2  s  .c o m

    Collections.addAll(list2, langs); 

    System.out.println(list2);
  }
}



PreviousNext

Related