Java Collection to Array asArray(Collection collection, E[] a)

Here you can find the source of asArray(Collection collection, E[] a)

Description

as Array

License

Open Source License

Declaration

static public <E> E[] asArray(Collection collection, E[] a) 

Method Source Code

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

import java.util.ArrayList;
import java.util.Collection;

import java.util.List;

public class Main {
    static public <E> E[] asArray(Collection collection, E[] a) {
        return asList(collection).toArray(a);
    }//from w  w  w.  j  a v  a  2s.c o m

    @SuppressWarnings("unchecked")
    static public <E> List<E> asList(Collection collection) {
        List<E> result = new ArrayList<E>();
        for (Object obj : collection) {
            result.add((E) obj);
        }
        return result;
    }

    @SuppressWarnings("unchecked")
    static public <E> List<E> asList(Collection collection, E[] a) {
        List<E> result = new ArrayList<E>();
        for (Object obj : collection) {
            result.add((E) obj);
        }
        return result;
    }
}

Related

  1. asArray(Collection c)
  2. asBooleanArray(Collection collection)
  3. asLongArray(final Collection ls)
  4. asLongArray(java.util.Collection c)
  5. collectionToArray(Collection collection)