Java ArrayList.toArray()
Syntax
ArrayList.toArray() has the following syntax.
public Object [] toArray()
Example
In the following code shows how to use ArrayList.toArray() method.
/*from ww w . jav a2s.c om*/
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> arrlist = new ArrayList<Integer> (5);
arrlist.add(20);
arrlist.add(40);
arrlist.add(10);
arrlist.add(15);
arrlist.add(25);
Object[] ob = arrlist.toArray();
System.out.println(Arrays.toString(ob));
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »