Android Enumeration to Array Convert toArray(Enumeration enumeration, A[] array)

Here you can find the source of toArray(Enumeration enumeration, A[] array)

Description

Marshal the elements from the given enumeration into an array of the given type.

Declaration

public static <A, E extends A> A[] toArray(Enumeration<E> enumeration,
        A[] array) 

Method Source Code

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

import java.util.Enumeration;

public class Main {
    /**/*from w w  w .j  a  v  a2 s.c  om*/
     * Marshal the elements from the given enumeration into an array of the given type.
     * Enumeration elements must be assignable to the type of the given array. The array
     * returned will be a different instance than the array given.
     */
    public static <A, E extends A> A[] toArray(Enumeration<E> enumeration,
            A[] array) {
        ArrayList<A> elements = new ArrayList<A>();
        while (enumeration.hasMoreElements()) {
            elements.add(enumeration.nextElement());
        }
        return elements.toArray(array);
    }
}

Related

  1. toArray(Enumeration enumeration, A[] array)