List of usage examples for java.util Collection toArray
default <T> T[] toArray(IntFunction<T[]> generator)
From source file:Main.java
@SuppressWarnings("unchecked") public static <E> E[] asArray(final Collection<? extends E> collection) { return collection.toArray((E[]) new Object[collection.size()]); }
From source file:Main.java
public static int[] toIntArray(Collection<Integer> list) { return toPrimitive(list.toArray(new Integer[0])); }
From source file:Main.java
/** USE NATIVE c.toArray(a) */ @Deprecated//from ww w . j av a 2 s . c o m public static <T> T[] toArray(Collection<T> c, T[] a) { return c.toArray(a); }
From source file:Main.java
public static <T> T[] convertArrayToList(Collection<T> list) { return (T[]) (list.size() > 0 ? list.toArray((Object[]) Array.newInstance(list.iterator().next().getClass(), list.size())) : null);//from w w w. ja va2 s . co m }
From source file:Main.java
/** * Calls the {@link Collection#toArray(Object[])} method constructing array based on the given argument type. * * @param <E>//from w w w.ja v a2s . c o m * the element type * @param collection * the collection * @param type * the type * @return the e[] */ @SuppressWarnings("unchecked") public static <E> E[] toArray(Collection<? extends E> collection, Class<E> type) { return collection.toArray((E[]) Array.newInstance(type, collection.size())); }
From source file:Main.java
public static String[] listToArrays(Collection<String> values) { String[] ret = new String[values.size()]; values.toArray(ret); return ret;//from w ww . j av a 2s . c o m }
From source file:Main.java
public static String split(Collection<?> collections, String separator) { Object[] array = collections.toArray(new Object[0]); int length = array.length; StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < length; i++) { stringBuilder.append(array[i]);// w w w. ja v a 2 s . com if (i != length - 1) { stringBuilder.append(separator); } } return stringBuilder.toString(); }
From source file:Main.java
public static Map<String, Object> toMap(Collection<String> names, Object[] parameters) { return toMap(names.toArray(new String[0]), parameters); }
From source file:Main.java
/** * Converts the given Collection into an array of the given type. * * @param collection The collection to convert * @param arrayType The type of array to return * @return The new array//w w w. j av a 2 s . c o m */ @SuppressWarnings({ "unchecked" }) public static <E> E[] toArray(Collection<E> collection, Class<? extends E> arrayType) { return collection.toArray((E[]) Array.newInstance(arrayType, collection.size())); }
From source file:Main.java
/** * To Array/*from w w w . j a va 2 s . c om*/ * * @param c * Collection * @return T[] */ @SuppressWarnings("unchecked") public static <T> T[] toArray(Collection<T> c) { if (c == null) { return null; } return (T[]) c.toArray(new Object[c.size()]); }