Java List to Array listToArray(List list)

Here you can find the source of listToArray(List list)

Description

list To Array

License

Apache License

Declaration

public static int[] listToArray(List<Integer> list) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;
import java.util.List;
import java.util.Map;

public class Main {

    public static int[] listToArray(List<Integer> list) {
        if (isEmpty(list)) {
            return null;
        }/*from w w w. j a  v  a  2 s  .  c  om*/
        int[] result = new int[list.size()];
        for (int i = 0; i < result.length; i++) {
            result[i] = list.get(i);
        }
        return result;
    }

    public static boolean isEmpty(Collection<?> col) {
        if (col == null || col.size() == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static <T> boolean isEmpty(T[] col) {
        if (col == null || col.length == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isEmpty(int[] array) {
        if (array == null || array.length == 0) {
            return true;
        }
        return false;
    }

    public static boolean isEmpty(double[] array) {
        if (array == null || array.length == 0) {
            return true;
        }
        return false;
    }

    public static boolean isEmpty(byte[] array) {
        if (array == null || array.length == 0) {
            return true;
        } else {
            return false;
        }
    }

    public static boolean isEmpty(Map<?, ?> map) {
        if (map == null || map.size() == 0) {
            return true;
        } else {
            return false;
        }
    }
}

Related

  1. listToArray(List list)
  2. listToArray(List doubles)
  3. listToArray(List list)
  4. listToArray(List list)
  5. ListToArray(List list)
  6. ListToArray(List> values)
  7. listToArray(List list)
  8. listToArray(List stringList)
  9. listToArray(List list)