Java Utililty Methods Collection to Array

List of utility methods to do Collection to Array

Description

The list of methods to do Collection to Array are organized into topic(s).

Method

Object[]toArray(T arrayOrCollection)
to Array
if (arrayOrCollection instanceof Collection) {
    return ((Collection) arrayOrCollection).toArray();
} else {
    return (Object[]) arrayOrCollection;
int[]toArrayInt(Collection integerCollection)
Returns the values of a Integer Collection as array.
int[] retvals = new int[integerCollection.size()];
int ii = 0;
for (Integer iValue : integerCollection) {
    retvals[ii++] = iValue;
return retvals;
char[][]toArrays(Collection strings)
to Arrays
char[][] arr = new char[strings.size()][];
int i = 0;
for (String str : strings) {
    arr[i++] = str.toCharArray();
return arr;
String[]toArrayString(Collection col, boolean spacing)
to Array String
int size = col.size();
if (spacing) {
    size++;
String[] result = new String[size];
int i = 0;
if (spacing) {
    result[i++] = "";
...
CollectiontoBaseTypedCollection(Collection initial)
Workaround for compile time checking of list types.
return (Collection<T>) initial;
byte[]toByteArray(Collection c)
to Byte Array
byte arr[] = new byte[c.size()];
int i = 0;
for (Number item : c)
    arr[i++] = item.byteValue();
return arr;
byte[]toByteArray(Collection c)
Converts a Collection of Bytes into a byte[] array.
int pos = 0;
byte byteArray[] = new byte[c.size()];
for (Byte id : c)
    byteArray[pos++] = id;
return byteArray;
char[]toCharArray(Collection source)
to Char Array
char[] result = new char[source.size()];
int i = 0;
for (Character c : source)
    result[i++] = c;
return result;
ListtoCharArray(Collection patterns)
to Char Array
List<char[]> charpatterns = new ArrayList<char[]>(patterns.size());
for (String pattern : patterns) {
    charpatterns.add(pattern.toCharArray());
return charpatterns;
Class[]toClassArray(Collection> collection)
Copy the given Collection into a Class array.
if (collection == null) {
    return null;
return collection.toArray(new Class<?>[collection.size()]);