Java tutorial
//package com.java2s; /* * Copyright (c) 2012 - Batoo Software ve Consultancy Ltd. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ import java.util.ArrayList; import java.util.Enumeration; public class Main { /** * 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. * * @param enumeration * the enumeration * @param array * the array * @return the array representation of the enumeration * @param <A> * the type of the array * @param <E> * the type of th enumeration */ public static <A, E extends A> A[] toArray(Enumeration<E> enumeration, A[] array) { final ArrayList<A> elements = new ArrayList<A>(); while (enumeration.hasMoreElements()) { elements.add(enumeration.nextElement()); } return elements.toArray(array); } }