Java List to Int List toIntArray(final List list)

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

Description

Convert integer list to array.

License

Open Source License

Parameter

Parameter Description
list Integer list to convert.

Return

Integer array.

Declaration

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

Method Source Code

//package com.java2s;
// and/or modify it under the terms of the GNU General Public License 

import java.util.List;

public class Main {
    /**//from   ww w  .  j  ava 2 s  . c  om
     * Convert integer list to array.
     * 
     * @param list
     *            Integer list to convert.
     * @return Integer array.
     */
    public static int[] toIntArray(final List<Integer> list) {
        int[] ret = new int[list.size()];
        int pos = 0;
        for (Integer it : list) {
            ret[pos] = it.intValue();
            ++pos;
        }
        return ret;
    }

    public static int intValue(final Object value) {
        if (value instanceof Byte) {
            return ((Byte) value).intValue() & 0xFF;
        }
        if (value instanceof Short) {
            return ((Short) value).intValue() & 0xFFFF;
        }
        return ((Number) value).intValue();
    }
}

Related

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