FileDocCategorySizeDatePackage
ToArray.javaAPI DocExample670Wed Mar 12 20:36:26 GMT 2003None

ToArray

public class ToArray extends Object
List to array

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

		List list = new ArrayList();
		list.add("Blobbo");
		list.add("Cracked");
		list.add("Dumbo");
		// list.add(new Date());	// Don't mix and match!

		// Convert a collection to Object[], which can store objects
		// of any type.
		Object[] ol = list.toArray();
		System.out.println("Array of Object has length " + ol.length);

		// This would throw an ArrayStoreException if the line
		// "list.add(new Date())" above were uncommented.
		String[] sl = (String[]) list.toArray(new String[0]);
		System.out.println("Array of String has length " + sl.length);