diff --git a/src/java/com/samskivert/util/CollectionUtil.java b/src/java/com/samskivert/util/CollectionUtil.java index fd276b84..5026bb16 100644 --- a/src/java/com/samskivert/util/CollectionUtil.java +++ b/src/java/com/samskivert/util/CollectionUtil.java @@ -20,6 +20,8 @@ package com.samskivert.util; +import java.lang.reflect.Array; + import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; @@ -148,6 +150,17 @@ public class CollectionUtil return subset; } + /** + * Returns an Array, of the type specified by the runtime-type token type, + * containing the elements of the collection. + */ + public static T[] toArray (Collection col, Class type) + { + @SuppressWarnings("unchecked") + T[] array = (T[]) Array.newInstance(type, col.size()); + return col.toArray(array); + } + /** * If a collection contains only Integer objects, it can be * passed to this function and converted into an int array.