Java Collection Tutorial - Java ArrayList(Collection <? extends E > c) Constructor








Syntax

ArrayList(Collection <? extends E > c) constructor from ArrayList has the following syntax.

public ArrayList(Collection <? extends E> c)

Example

In the following code shows how to use ArrayList.ArrayList(Collection <? extends E > c) constructor.

/* w  w w .  jav a2 s .co  m*/

import java.util.ArrayList;
import java.util.Collection;

public class Main {
  public static void main(String args[]) {
    Collection<Integer>  arrlist = new ArrayList<Integer> ();
  
    arrlist.add(1);
    arrlist.add(2);
    arrlist.add(3);
    arrlist.add(4);
    arrlist.add(5);

    
    ArrayList<Integer> anotherList = new ArrayList<Integer>(arrlist);
    System.out.println(anotherList);


  }
}

The code above generates the following result.