Here you can find the source of toObject(long[] array)
Converts an array of primitive longs to objects.
This method returns null
for a null
input array.
Parameter | Description |
---|---|
array | a <code>long</code> array |
Long
array, null
if null array input
public static Long[] toObject(long[] array)
//package com.java2s; /*//from w w w .ja v a 2s. c o m * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * An empty immutable <code>Long</code> array. */ public static final Long[] EMPTY_LONG_OBJECT_ARRAY = new Long[0]; /** * An empty immutable <code>Integer</code> array. */ public static final Integer[] EMPTY_INTEGER_OBJECT_ARRAY = new Integer[0]; /** * An empty immutable <code>Short</code> array. */ public static final Short[] EMPTY_SHORT_OBJECT_ARRAY = new Short[0]; /** * An empty immutable <code>Byte</code> array. */ public static final Byte[] EMPTY_BYTE_OBJECT_ARRAY = new Byte[0]; /** * An empty immutable <code>Double</code> array. */ public static final Double[] EMPTY_DOUBLE_OBJECT_ARRAY = new Double[0]; /** * An empty immutable <code>Float</code> array. */ public static final Float[] EMPTY_FLOAT_OBJECT_ARRAY = new Float[0]; /** * An empty immutable <code>Boolean</code> array. */ public static final Boolean[] EMPTY_BOOLEAN_OBJECT_ARRAY = new Boolean[0]; /** * An empty immutable <code>Character</code> array. */ public static final Character[] EMPTY_CHARACTER_OBJECT_ARRAY = new Character[0]; /** * <p>Converts an array of primitive chars to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array a <code>char</code> array * @return a <code>Character</code> array, <code>null</code> if null array input */ public static Character[] toObject(char[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_CHARACTER_OBJECT_ARRAY; } final Character[] result = new Character[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Character.valueOf(array[i]); } return result; } /** * <p>Converts an array of primitive longs to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array a <code>long</code> array * @return a <code>Long</code> array, <code>null</code> if null array input */ public static Long[] toObject(long[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_LONG_OBJECT_ARRAY; } final Long[] result = new Long[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Long.valueOf(array[i]); } return result; } /** * <p>Converts an array of primitive ints to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array an <code>int</code> array * @return an <code>Integer</code> array, <code>null</code> if null array input */ public static Integer[] toObject(int[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_INTEGER_OBJECT_ARRAY; } final Integer[] result = new Integer[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Integer.valueOf(array[i]); } return result; } /** * <p>Converts an array of primitive shorts to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array a <code>short</code> array * @return a <code>Short</code> array, <code>null</code> if null array input */ public static Short[] toObject(short[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_SHORT_OBJECT_ARRAY; } final Short[] result = new Short[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Short.valueOf(array[i]); } return result; } /** * <p>Converts an array of primitive bytes to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array a <code>byte</code> array * @return a <code>Byte</code> array, <code>null</code> if null array input */ public static Byte[] toObject(byte[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_BYTE_OBJECT_ARRAY; } final Byte[] result = new Byte[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Byte.valueOf(array[i]); } return result; } /** * <p>Converts an array of primitive doubles to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array a <code>double</code> array * @return a <code>Double</code> array, <code>null</code> if null array input */ public static Double[] toObject(double[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_DOUBLE_OBJECT_ARRAY; } final Double[] result = new Double[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Double.valueOf(array[i]); } return result; } /** * <p>Converts an array of primitive floats to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array a <code>float</code> array * @return a <code>Float</code> array, <code>null</code> if null array input */ public static Float[] toObject(float[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_FLOAT_OBJECT_ARRAY; } final Float[] result = new Float[array.length]; for (int i = 0; i < array.length; i++) { result[i] = Float.valueOf(array[i]); } return result; } /** * <p>Converts an array of primitive booleans to objects.</p> * * <p>This method returns <code>null</code> for a <code>null</code> input array.</p> * * @param array a <code>boolean</code> array * @return a <code>Boolean</code> array, <code>null</code> if null array input */ public static Boolean[] toObject(boolean[] array) { if (array == null) { return null; } else if (array.length == 0) { return EMPTY_BOOLEAN_OBJECT_ARRAY; } final Boolean[] result = new Boolean[array.length]; for (int i = 0; i < array.length; i++) { result[i] = (array[i] ? Boolean.TRUE : Boolean.FALSE); } return result; } }