List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:Main.java
/** * Copies a collection into an array.// w w w .ja va 2 s .c om * * @param collection * is the collection that should be copied to an array * @param type * is the class of the elements in the collection * @return the array copy */ public static <T> T[] toArray(final Collection<T> collection, final Class<T> type) { final int size = collection.size(); @SuppressWarnings("unchecked") final T[] array = (T[]) Array.newInstance(type, size); collection.toArray(array); return array; }
From source file:com.google.code.guice.repository.configuration.RepositoriesGroupBuilder.java
public static RepositoriesGroupBuilder forPackages(Collection<String> repositoriesPackages) { Assert.notEmpty(repositoriesPackages); Assert.noNullElements(repositoriesPackages.toArray(new String[repositoriesPackages.size()])); return new RepositoriesGroupBuilder(repositoriesPackages); }
From source file:com.aionemu.commons.utils.PropertiesUtils.java
/** * Loads all .property files form directory * * @param dir directory//from w w w . j a v a2 s.c o m * @param recursive parse subdirectories or not * @return array of loaded properties * @throws IOException if was unable to read properties */ @SuppressWarnings("unchecked") public static Properties[] loadAllFromDirectory(File dir, boolean recursive) throws IOException { Collection<File> files = FileUtils.listFiles(dir, new String[] { "properties" }, recursive); return load(files.toArray(new File[files.size()])); }
From source file:StringUtils.java
public static String[] toStringArray(Collection collection) { if (collection == null) { return null; }/*from w w w . ja v a2 s .com*/ return (String[]) collection.toArray(new String[collection.size()]); }
From source file:com.judoscript.jamaica.MyUtils.java
public static String[] toStringArray(Collection<String> col) { return col.toArray(new String[col.size()]); }
From source file:Main.java
public static <T> String[] compact(Collection<T> col) { Collection<String> result = new ArrayList(); for (T e : col) { String str = e.toString(); if (!str.trim().isEmpty()) result.add(str);// w ww . j a va 2 s. co m } return result.toArray(new String[result.size()]); }
From source file:net.dv8tion.jda.core.Permission.java
public static long getRaw(Collection<Permission> permissions) { Args.notNull(permissions, "Permission Collection"); return getRaw(permissions.toArray(new Permission[permissions.size()])); }
From source file:com.kwoksys.framework.util.StringUtils.java
/** * Joins a list of strings.// w w w . ja v a 2 s.com * @param strings * @param token * @return */ public static String join(Collection<String> strings, String token) { return join(strings.toArray(new String[strings.size()]), token); }
From source file:Main.java
@SuppressWarnings("unchecked") public static <T> T[] merge(T[] c1, Collection<T> c2) { return merge(c1, c2 == null ? null : (T[]) c2.toArray(new Object[0])); }
From source file:com.facebook.hiveio.mapreduce.output.WritingTool.java
/** * add string to collection//from w w w .j ava2 s . c o m * * @param conf Configuration * @param name to add * @param values values for collection */ private static void addToStringCollection(Configuration conf, String name, Collection<? extends String> values) { Collection<String> tmpfiles = conf.getStringCollection(name); tmpfiles.addAll(values); conf.setStrings(name, tmpfiles.toArray(new String[tmpfiles.size()])); }