Java Array to ArrayList asArrayList(Collection c)

Here you can find the source of asArrayList(Collection c)

Description

as Array List

License

Open Source License

Declaration

public static ArrayList asArrayList(Collection c) 

Method Source Code


//package com.java2s;

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

public class Main {
    public static ArrayList asArrayList(Collection c) {
        return (ArrayList) asTargetTypeCollection(c, ArrayList.class);
    }// w ww . j a v a  2 s .  c  om

    public static Collection asTargetTypeCollection(Collection c, Class targetCollectionClass) {
        if (targetCollectionClass == null)
            throw new IllegalArgumentException("'targetCollectionClass' must be not null");
        if (c == null)
            return null;
        if (targetCollectionClass.isInstance(c))
            return c;

        Collection result = null;

        try {
            result = (Collection) targetCollectionClass.newInstance();
        } catch (Exception e) {
            throw new IllegalArgumentException(
                    "targetCollectionClass=" + targetCollectionClass.getName() + " is not correct!", e);
        }

        result.addAll(c);
        return result;
    }
}

Related

  1. arrayToArrayList(Object[] array)
  2. arrayToArrayList(Object[] myArray)
  3. arrayToArraylist(String[] array)
  4. arrayToArrayList(T[] array)
  5. arrayToArraylist(T[] array)
  6. asArrayList(T... elements)
  7. asArrayList(T[] tArray)
  8. asArrayList(T[] values)
  9. byteArrayToArrayList(byte[] byteArray)