Java Object Create toObject(int[] array)

Here you can find the source of toObject(int[] array)

Description

Converts a int array to a Integer array.

License

Open Source License

Parameter

Parameter Description
array the input array, not null

Return

the output array, not null

Declaration

public static Integer[] toObject(int[] array) 

Method Source Code

//package com.java2s;
/**//  w w w .j  a v  a2  s  . c o m
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 * 
 * Please see distribution for license.
 */

public class Main {
    /**
     * An empty array.
     */
    public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY = new Integer[0];
    /**
     * An empty array.
     */
    public static final Long[] EMPTY_LONG_OBJECT_ARRAY = new Long[0];
    /**
     * An empty array.
     */
    public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY = new Double[0];

    /**
     * Converts a {@code int} array to a {@code Integer} array.
     *
     * @param array  the input array, not null
     * @return the output array, not null
     */
    public static Integer[] toObject(int[] array) {
        if (array.length == 0) {
            return EMPTY_INTEGER_OBJECT_ARRAY;
        }
        Integer[] result = new Integer[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i];
        }
        return result;
    }

    /**
     * Converts a {@code long} array to a {@code Long} array.
     *
     * @param array  the input array, not null
     * @return the output array, not null
     */
    public static Long[] toObject(long[] array) {
        if (array.length == 0) {
            return EMPTY_LONG_OBJECT_ARRAY;
        }
        Long[] result = new Long[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i];
        }
        return result;
    }

    /**
     * Converts a {@code double} array to a {@code Double} array.
     *
     * @param array  the input array, not null
     * @return the output array, not null
     */
    public static Double[] toObject(double[] array) {
        if (array.length == 0) {
            return EMPTY_DOUBLE_OBJECT_ARRAY;
        }
        Double[] result = new Double[array.length];
        for (int i = 0; i < array.length; i++) {
            result[i] = array[i];
        }
        return result;
    }
}

Related

  1. toObject(byte[] byteArray)
  2. toObject(byte[] primitiveArray)
  3. toObject(Class clazz, String value)
  4. toObject(double[] a)
  5. toObject(final int i)
  6. toObject(int[] values)
  7. toObject(long[] array)
  8. toObject(Object value)
  9. toObject(short s)