Last active
December 19, 2015 05:39
-
-
Save xCASx/5905279 to your computer and use it in GitHub Desktop.
Convert a collection to the array.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Convert a Collection to the array of {@link Class<T[]>} type | |
* @param type class of outgoing array | |
* @param collection collection which should be converted | |
* @param <T> base type for outgoing array | |
* @return outgoing array {@link Class<T[]>} | |
*/ | |
private static <T> T[] convertCollectionToArray(Class<T[]> type, Collection collection) { | |
T[] t = type.cast(Array.newInstance(type.getComponentType(), collection.size())); | |
return (T[]) collection.toArray(t); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment