Java Collection to Array asArray(Collection c)

Here you can find the source of asArray(Collection c)

Description

Returns an array with the elements in a given collection.

License

Open Source License

Declaration

public static Object[] asArray(Collection c) 

Method Source Code

//package com.java2s;

import java.util.Collection;
import java.util.Iterator;

public class Main {
    /** Returns an array with the elements in a given collection. */
    public static Object[] asArray(Collection c) {
        Object[] array = new Object[c.size()];
        int i = 0;
        for (Iterator it = c.iterator(); it.hasNext();) {
            array[i++] = it.next();/*from   w  ww. ja  v  a2  s  .  c  o  m*/
        }
        return array;
    }
}

Related

  1. asArray(Collection collection, E[] a)
  2. asBooleanArray(Collection collection)
  3. asLongArray(final Collection ls)
  4. asLongArray(java.util.Collection c)