集册 Java实例教程 转换为ArrayList

转换为ArrayList

欢马劈雪     最近更新时间:2020-01-02 10:19:05

468
转换为ArrayList
/*时 代 J a v a 提 供*/


//package com.book2s;

import java.util.ArrayList;


import java.util.Collection;


import java.util.Set;


public class Main {

    /**

     * @param array A collection of elements to be included in the returned ArrayList

     * @return An ArrayList that includes all the elements passed in via the array parameter

     */

    public static <T> ArrayList<T> toArrayList(final T... array) {

        final ArrayList<T> retValue = new ArrayList<T>();

        for (final T item : array)
        /*
         from 时 代 J a v a 公 众 号 - nowjava.com 
        */

            retValue.add(item);

        return retValue;

    }


    /**

     * @param set The Set to be converted to an ArrayList

     * @return An ArrayList containing the elements in the set

     */

    public static <T> ArrayList<T> toArrayList(final Set<T> set) {

        final ArrayList<T> retValue = new ArrayList<T>();

        for (final T item : set)

            retValue.add(item);

        return retValue;

    }


    /**

     * @param items The Collection of items to be converted to an ArrayList

     * @return An ArrayList containing the elements in the set

     */

    public static <T> ArrayList<T> toArrayList(
展开阅读全文