Java Integer Create toInt(long l)

Here you can find the source of toInt(long l)

Description

Converts long value to int under the conditions that the long value is representable as an int.

License

Open Source License

Exception

Parameter Description
IllegalArgumentException if the is greater than the biggest int

Declaration

private static int toInt(long l) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w w  w .  j a v  a2s  .  c  o m
     * Converts long value to int under the conditions that the long value is representable
     * as an int.
     * @throws  IllegalArgumentException if the {@l} is greater than the biggest int
     */
    private static int toInt(long l) {
        if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
            throw new IllegalArgumentException(l + " cannot be cast to int without changing its value.");
        }
        return (int) l;
    }
}

Related

  1. toInt(float value)
  2. toInt(int byteSignificance, byte b)
  3. toInt(int[] rgb)
  4. toInt(Integer i)
  5. toInt(Integer n)
  6. toInt(long l)
  7. toInt(long unsignedInt)
  8. toInt(long[] a)
  9. toInt(Number num)