Example usage for java.util Collection toArray

List of usage examples for java.util Collection toArray

Introduction

In this page you can find the example usage for java.util Collection toArray.

Prototype

default <T> T[] toArray(IntFunction<T[]> generator) 

Source Link

Document

Returns an array containing all of the elements in this collection, using the provided generator function to allocate the returned array.

Usage

From source file:ArrayHelper.java

public static int[][] to2DIntArray(Collection coll) {
    return (int[][]) coll.toArray(new int[coll.size()][]);
}

From source file:ArrayHelper.java

public static String[] toStringArray(Collection coll) {
    return (String[]) coll.toArray(EMPTY_STRING_ARRAY);
}

From source file:com.dsh105.commodus.StringUtil.java

/**
 * Combines a collection of strings into a single string, separated by the given character set
 *
 * @param startIndex       index to begin the separation at, inclusive
 * @param separator        character set included between each part of the given array
 * @param stringCollection collection of strings to combine
 * @return the combined string/*from  w w w . ja  va 2  s. c  om*/
 */
public static String combine(int startIndex, String separator, Collection<String> stringCollection) {
    return combineArray(startIndex, separator, stringCollection.toArray(EMPTY_STRING_ARRAY));
}

From source file:ArrayHelper.java

public static String[][] to2DStringArray(Collection coll) {
    return (String[][]) coll.toArray(new String[coll.size()][]);
}

From source file:com.google.code.guice.repository.configuration.ScanningJpaRepositoryModule.java

private static String[] extractPersistenceUnitsNames(Iterable<RepositoriesGroup> repositoriesGroups) {
    Collection<String> persistenceUnitsNames = new ArrayList<String>();
    for (RepositoriesGroup repositoriesGroup : repositoriesGroups) {
        persistenceUnitsNames.add(repositoriesGroup.getPersistenceUnitName());
    }/*from   w ww.  j a  v a 2 s .co m*/

    return persistenceUnitsNames.toArray(new String[persistenceUnitsNames.size()]);
}

From source file:com.dsh105.commodus.StringUtil.java

/**
 * Combines a collection of strings into a single string, separated by the given character set
 *
 * @param startIndex       index to begin the separation at, inclusive
 * @param endIndex         index to end the separation at, exclusive
 * @param separator        character set included between each part of the given array
 * @param stringCollection collection of strings to combine
 * @return the combined string//from w w w  .  j ava 2 s . c o m
 */
public static String combine(int startIndex, int endIndex, String separator,
        Collection<String> stringCollection) {
    return combineArray(startIndex, endIndex, separator, stringCollection.toArray(EMPTY_STRING_ARRAY));
}

From source file:com.fengduo.bee.commons.core.lang.BeanUtils.java

public static <T extends Object> void copyProperties(T target, Object raw,
        Collection<? extends ValueEditable> convert) {
    copyProperties(target, raw, convert.toArray(new ValueEditable[0]));
}

From source file:com.qmetry.qaf.automation.util.FileUtil.java

public static File[] listFilesAsArray(File directory, FilenameFilter filter, boolean recurse) {
    Collection<File> files = listFiles(directory, filter, recurse);
    File[] arr = new File[files.size()];
    return files.toArray(arr);
}

From source file:com.qmetry.qaf.automation.util.FileUtil.java

public static File[] listFilesAsArray(File directory, String fname, StringComparator c, boolean recurse) {
    Collection<File> files = listFiles(directory, fname, c, recurse);
    File[] arr = new File[files.size()];
    return files.toArray(arr);
}

From source file:com.github.juanmf.java2plant.Parser.java

private static Collection<URL> getUrls(List<ClassLoader> classLoadersList) {
    classLoadersList.add(ClasspathHelper.contextClassLoader());
    classLoadersList.add(ClasspathHelper.staticClassLoader());
    Collection<URL> urls = ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]));
    CLASS_LOADER = new URLClassLoader(urls.toArray(new URL[0]));
    return urls;/*from   w  w  w .j a v  a 2 s  .  com*/
}