public Object[] toArray()
public Object[] toArray(Object[] a)
The first toArray() method returns an Object array.
The second version returns an array of a specific type, Object or otherwise.
import java.util.Arrays;
import java.util.List;
public class MainClass {
public static void main(String[] a) {
List list = Arrays.asList(new String[] { "A", "B", "C", "D" });
Object[] objArray = list.toArray();
for (Object obj : objArray) {
System.out.println(obj);
}
String[] strArray = (String[]) list.toArray(new String[list.size()]);
for (String string : strArray) {
System.out.println(string);
}
}
}
A
B
C
D
A
B
C
D