Java Collection to Array toArray(Collection collection)

Here you can find the source of toArray(Collection collection)

Description

Cast a collection to an array

License

Open Source License

Parameter

Parameter Description
collection the collection to cast
T the type of the collection contents

Return

an array of type T

Declaration

public static <T> T[] toArray(Collection<T> collection) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Collection;

public class Main {
    /**//  www .  ja  v  a 2s  .  c o  m
     * Cast a collection to an array
     *
     * @param collection the collection to cast
     * @param <T>        the type of the collection contents
     * @return an array of type T
     */
    public static <T> T[] toArray(Collection<T> collection) {
        return (T[]) collection.toArray(new Object[collection.size()]);
    }
}

Related

  1. toArray(Collection list)
  2. toArray(Collection stringCollection)
  3. toArray(Collection strings)
  4. toArray(Collection values)
  5. toArray(Collection c, T[] sample)
  6. toArray(Collection list, Object[] type)
  7. toArray(final Collection c)
  8. toArray(final Collection coll, byte[] array)
  9. toArray(final Collection collection)