Java ArrayList Create toArrayList(String[] stringArray)

Here you can find the source of toArrayList(String[] stringArray)

Description

Creates a new ArrayList, containing the elements of a supplied array of String objects.

License

Apache License

Parameter

Parameter Description
stringArray The array of <code>String</code> objects that have to be converted.

Return

The new ArrayList with the elements of the String array.

Declaration

public static List<String> toArrayList(String[] stringArray) 

Method Source Code

//package com.java2s;
/*//  w ww  .ja va 2  s . c  o  m
 * Copyright 2001-2013 Geert Bevin (gbevin[remove] at uwyn dot com)
 * Licensed under the Apache License, Version 2.0 (the "License")
 */

import java.util.*;

public class Main {
    /**
     * Creates a new <code>ArrayList</code>, containing the elements of a
     * supplied array of <code>String</code> objects.
     *
     * @param stringArray The array of <code>String</code> objects that have
     *                    to be converted.
     * @return The new <code>ArrayList</code> with the elements of the
     *         <code>String</code> array.
     * @since 1.0
     */
    public static List<String> toArrayList(String[] stringArray) {
        List<String> strings = new ArrayList<>();

        if (null == stringArray) {
            return strings;
        }

        Collections.addAll(strings, stringArray);

        return strings;
    }
}

Related

  1. sizedArrayList(int capacity)
  2. stringToArrayList(String s, String sep)
  3. stringToArrayList(String string)
  4. toArrayList(int[] intValues)
  5. toArrayList(Iterator ii, int initial_capacity)