Java Collection to String asStringArray(Collection coll)

Here you can find the source of asStringArray(Collection coll)

Description

Convert the collection to a string array.

License

Open Source License

Parameter

Parameter Description
coll a parameter

Return

string array

Declaration

public static String[] asStringArray(Collection<? extends Object> coll) 

Method Source Code

//package com.java2s;
/*/* ww w.j a v a  2  s.  c  o m*/
 *  Copyright (c) Ludger Solbach. All rights reserved.
 *  The use and distribution terms for this software are covered by the
 *  Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 *  which can be found in the file license.txt at the root of this distribution.
 *  By using this software in any fashion, you are agreeing to be bound by
 *  the terms of this license.
 *  You must not remove this notice, or any other, from this software.
 */

import java.util.Collection;

public class Main {
    /**
     * Convert the collection to a string array. The method toString() is called on every entry.
     * @param coll
     * @return string array
     */
    public static String[] asStringArray(Collection<? extends Object> coll) {
        int i = 0;
        String[] strings = new String[coll.size()];
        for (Object o : coll) {
            strings[i++] = o.toString();
        }
        return strings;
    }
}

Related

  1. asString(Collection c, String separator)
  2. asString(Collection collection)
  3. asStringArr(Collection collection)
  4. asStringArray(Collection collection)
  5. buildString(Collection args, String seperator, int startingArg, int maxLength)
  6. buildString(Collection keys)
  7. buildStringFromListForNuma(Collection list)