Java List to Int List toIntArray(final List list)

Here you can find the source of toIntArray(final List list)

Description

to Int Array

License

LGPL

Declaration

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

Method Source Code


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

import java.util.*;

public class Main {
    public static int[] toIntArray(final List<Integer> list) {
        int[] array = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            array[i] = list.get(i);//from   ww w . j a va  2  s.  co m
        }
        return array;
    }

    public static int size(final Object[] array) {
        return null != array ? array.length : 0;
    }

    public static int size(final Collection collection) {
        return null != collection ? collection.size() : 0;
    }

    public static int size(final Map map) {
        return null != map ? map.size() : 0;
    }

    public static <T> T get(T[] array, int index) {
        if (array.length < index + 1) {
            return null;
        }
        return array[index];
    }

    public static <T> T get(final T[] array, final int index, final T defaultValue) {
        if (array.length < index + 1) {
            return defaultValue;
        }
        final T result = array[index];
        return null != result ? result : defaultValue; // array[index];
    }

    public static <T> T get(final Collection<T> collection, final int index) {
        if (collection.size() < index + 1) {
            return null;
        }
        int i = 0;
        for (T item : collection) {
            if (i == index) {
                return item;
            }
            i++;
        }
        return null;
    }
}

Related

  1. listToIntArray(List l)
  2. listToIntArray(List list)
  3. listToIntegerArray(List list)
  4. toIntArray(final List numbers)
  5. toIntArray(final List list)
  6. toIntArray(final List list)
  7. toIntArray(java.util.List list)
  8. toIntArray(List list)
  9. toIntArray(List nums)