Java Collection to Array toStringArray(Collection collection)

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

Description

Returns an array containing string representations of the elements in the collection.

License

Apache License

Parameter

Parameter Description
collection the collection

Return

the array

Declaration

public static String[] toStringArray(Collection<?> collection) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Collection;

public class Main {
    /**/*ww  w  . j  a v a2s  . co  m*/
     * Returns an array containing string representations of the elements in the collection.
     * 
     * @param collection the collection
     * @return the array
     */
    public static String[] toStringArray(Collection<?> collection) {
        String[] result = new String[collection.size()];
        int index = 0;

        for (Object entry : collection) {
            result[index] = String.valueOf(entry);

            index += 1;
        }

        return result;
    }
}

Related

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