Java tutorial
//package com.java2s; /* * Copyright JTheque (Baptiste Wicht) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.List; public class Main { /** * Convert the enumeration to a collection. * * @param enumeration The enumeration to convert to Collection. * @param <T> The type of object stored in the enumeration. * * @return A Collection containing all the elements of the enumeration. */ public static <T> Collection<T> toCollection(Enumeration<T> enumeration) { Collection<T> collection = newList(25); while (enumeration.hasMoreElements()) { collection.add(enumeration.nextElement()); } return collection; } /** * Create a new list with a capacity of 10. * * @param <T> The type of data. * * @return The new list. */ public static <T> List<T> newList() { return new ArrayList<T>(10); } /** * Create a new list with the given capacity. * * @param <T> The type of data. * @param capacity The initial capacity of the list. * * @return The new list. */ public static <T> List<T> newList(int capacity) { return new ArrayList<T>(capacity); } }