Java Integer Create toIntArray(long[] in)

Here you can find the source of toIntArray(long[] in)

Description

Convert long array to integer array

License

Open Source License

Parameter

Parameter Description
in a parameter

Return

integer array

Declaration

public static int[] toIntArray(long[] in) 

Method Source Code

//package com.java2s;
/*-//from  w w w  .jav  a  2s .  c  o  m
 * Copyright 2015 Diamond Light Source Ltd.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    /**
     * Convert long array to integer array
     * @param in
     * @return integer array
     */
    public static int[] toIntArray(long[] in) {
        int[] out = new int[in.length];
        for (int i = 0; i < out.length; i++) {
            long value = in[i];
            if (value == Long.MAX_VALUE) {
                value = -1; // stopgap fix for incorrectly written maximum shape
            }
            if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) {
                throw new IllegalArgumentException("Cannot convert to int array without data loss");
            }
            out[i] = (int) value;
        }
        return out;
    }
}

Related

  1. toIntArray(final String[] arrayOfIntStrings)
  2. toIntArray(int... values)
  3. toIntArray(Integer[] data)
  4. toIntArray(Integer[] objArray)
  5. toIntArray(long color)
  6. toIntArray(String intArray)
  7. toIntArray(String src)
  8. toIntArray(String str, String delimiter)
  9. toIntArray(String str, String separator)