Java Integer Create toInts(Integer[] values)

Here you can find the source of toInts(Integer[] values)

Description

to Ints

License

Open Source License

Declaration

public static int[] toInts(Integer[] values) 

Method Source Code

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

public class Main {
    public static final int DEFAULT_INT = 0;

    public static int[] toInts(Integer[] values) {
        return toInts(values, DEFAULT_INT);
    }/*from w w w .j av  a  2 s .  co  m*/

    public static int[] toInts(Integer[] values, int defaultValue) {
        int[] results = new int[0];
        if (values != null) {
            results = new int[values.length];
            for (int i = 0; i < results.length; i++) {
                Integer element = values[i];
                try {
                    results[i] = (element != null ? element.intValue()
                            : defaultValue);
                } catch (Exception ex) {
                    // ex.printStackTrace();
                }
            }
        }
        return results;
    }

    public static Integer[] toInts(int[] values) {
        return toInts(values, DEFAULT_INT);
    }

    public static Integer[] toInts(int[] values, int defaultValue) {
        Integer[] results = new Integer[0];
        if (values != null) {
            results = new Integer[values.length];
            for (int i = 0; i < results.length; i++) {
                int element = values[i];
                try {
                    results[i] = new Integer(element);
                } catch (Exception ex) {
                    results[i] = defaultValue;
                    // ex.printStackTrace();
                }
            }
        }
        return results;
    }
}

Related

  1. toInts(byte[] readBuffer, int o, int l)
  2. toInts(byte[] src, int srcOffset, int[] dst, int dstOffset, int length)
  3. toInts(byte[] value, int offset, int num)
  4. toInts(double[] arr)
  5. toInts(int val)
  6. toInts(long[] array)
  7. toInts(String intArray)
  8. toInts(String[] values)
  9. toIntsFromUBytes(byte[] byteArray)