Java Array to List toList(String[] array)

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

Description

to List

License

Open Source License

Declaration

public static final List<String> toList(String[] array) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class Main {
    public static final List<String> toList(String[] array) {
        return let(array, null);
    }//  w  w w . ja  v a 2s .  co m

    @SuppressWarnings("unchecked")
    public static final <T extends Collection<String>> T let(String[] array, Class<T> tClazz) {
        T result = null;
        if (null == tClazz) {
            result = (T) new ArrayList<String>();
        } else {
            try {
                result = tClazz.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (null != array && array.length > 0) {
            for (String e : array) {
                result.add(e);
            }
        }
        return result;
    }
}

Related

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