Java Collection to Array toStringArray(Collection collection)

Here you can find the source of toStringArray(Collection collection)

Description

Copy the given Collection into a String array.

License

Open Source License

Parameter

Parameter Description
collection the Collection to copy

Return

the String array (null if the passed-in Collection was null)

Declaration

@SuppressWarnings({ "unchecked" })
public static String[] toStringArray(Collection collection) 

Method Source Code

//package com.java2s;
/**/*from w w w. j  a va2 s .com*/
 * <p>
 * Simple utility class for String operations useful across the framework.
 * <p/>
 * <p>
 * Some methods in this class were copied from the Spring Framework so we didn't
 * have to re-invent the wheel, and in these cases, we have retained all
 * license, copyright and author information.
 *
 * @since 0.9
 */

import java.util.*;

public class Main {
    /**
     * Copy the given Collection into a String array. The Collection must
     * contain String elements only.
     * <p/>
     * <p>
     * Copied from the Spring Framework while retaining all license, copyright
     * and author information.
     *
     * @param collection the Collection to copy
     * @return the String array (<code>null</code> if the passed-in Collection
     * was <code>null</code>)
     */
    @SuppressWarnings({ "unchecked" })
    public static String[] toStringArray(Collection collection) {
        if (collection == null) {
            return null;
        }
        return (String[]) collection.toArray(new String[collection.size()]);
    }
}

Related

  1. toIntArray(final Collection col)
  2. toIntArray(final Collection collection)
  3. toIntArray(final Collection values)
  4. toLongArray(Collection collection)
  5. toLongArray(Collection collection)
  6. toStringArray(Collection collection)
  7. toStringArray(Collection collection)
  8. toStringArray(Collection collection)
  9. toStringArray(Collection collection)