Java Collection Tutorial - Java List.toArray(T[] a)








Syntax

List.toArray(T[] a) has the following syntax.

<T> T[] toArray(T[] a)

Example

In the following code shows how to use List.toArray(T[] a) method.

/*  w w w.  ja  v  a  2 s  .  com*/
import java.util.Arrays;
import java.util.List;

public class Main {
  public static void main(String args[]) {
    String[] a = new String[] { "a", "c", "b" };

    List l = (Arrays.asList());
    String stuff[] = (String[]) l.toArray(new String[0]);
  }
}