Here you can find the source of toArray(Collection c)
Parameter | Description |
---|---|
c | Collection of String object. |
Parameter | Description |
---|---|
ClassCastException | if the object in the Collection isnot a String object. |
public static String[] toArray(Collection c)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { private static final String[] EMPTY_STRING_ARRAY = new String[0]; /**/* w w w . j a v a2 s . co m*/ * Returns a string array contains all the String object in the * Collection c. * * @param c * Collection of String object. * @throws ClassCastException * if the object in the Collection is * not a String object. * * @author chenke */ public static String[] toArray(Collection c) { if (c == null || c.size() == 0) { return EMPTY_STRING_ARRAY; } String[] result = new String[c.size()]; int i = 0; for (Iterator iter = c.iterator(); iter.hasNext();) { result[i++] = (String) iter.next(); } return result; } }