Java Collection to Array toArray(final Collection collection)

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

Description

to Array

License

Open Source License

Declaration

public static int[] toArray(final Collection<Integer> collection) 

Method Source Code


//package com.java2s;
import java.util.Collection;

public class Main {
    public static int[] toArray(final Collection<Integer> collection) {
        if (collection == null || collection.isEmpty()) {
            return new int[0];
        }//from   w ww .  j a v a  2  s .com
        final int[] result = new int[collection.size()];
        int index = 0;
        for (final Integer integer : collection) {
            result[index] = integer.intValue();
            index++;
        }
        return result;
    }
}

Related

  1. toArray(Collection c, T[] sample)
  2. toArray(Collection collection)
  3. toArray(Collection list, Object[] type)
  4. toArray(final Collection c)
  5. toArray(final Collection coll, byte[] array)
  6. toArray(final Collection collection)
  7. toArray(java.util.Collection collection)
  8. toArray(T arrayOrCollection)
  9. toArrayInt(Collection integerCollection)