Java Array to List toList(String[] array)

Here you can find the source of toList(String[] array)

Description

Creates a new ArrayList collection from the specified array of Strings.

License

Open Source License

Parameter

Parameter Description
array the array

Return

newly created .

Declaration

public static ArrayList<String> toList(String[] array) 

Method Source Code


//package com.java2s;
/*//from  w  w  w .java  2  s.co m
 Copyright (C) 2010 by
 * 
 *    Cam-Tu Nguyen 
 *  ncamtu@ecei.tohoku.ac.jp or ncamtu@gmail.com
 *
 *  Xuan-Hieu Phan  
 *  pxhieu@gmail.com 
 *
 *  College of Technology, Vietnamese University, Hanoi
 *    Graduate School of Information Sciences, Tohoku University
 *
 * JVnTextPro-v.2.0 is a free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published
 * by the Free Software Foundation; either version 2 of the License,
 * or (at your option) any later version.
 *
 * JVnTextPro-v.2.0 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with  JVnTextPro-v.2.0); if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */

import java.util.ArrayList;

import java.util.Set;

public class Main {
    /**
     * Creates a new <tt>ArrayList</tt> collection from the specified array of <tt>String</tt>s.
     *
     * @param array the array
     * @return  newly created .
     */
    public static ArrayList<String> toList(String[] array) {
        if (array == null) {
            return new ArrayList<String>(0);
        }
        ArrayList<String> list = new ArrayList<String>(array.length);
        for (String s : array) {
            list.add(s);
        }
        return list;
    }

    /**
     * Creates a new <tt>ArrayList</tt> collection from the specified <tt>Set</tt> of <tt>String</tt>s.
     *
     * @param set   a set of <tt>String</tt>s.
     * @return newly created .
     */
    public static ArrayList<String> toList(Set<String> set) {
        int n = set.size();
        ArrayList<String> list = new ArrayList<String>(n);
        for (String string : set) {
            list.add(string);
        }
        return list;
    }
}

Related

  1. toList(Object[] data)
  2. toList(Object[] input)
  3. toList(String[] anArray)
  4. toList(String[] arr)
  5. toList(String[] array)
  6. toList(T element, T... elements)
  7. toList(T value)
  8. toList(T... elements)
  9. toList(T... items)