Convert long value to byte, double, float, int, long, short

byte byteValue()
Returns the value of this Long as a byte.
double doubleValue()
Returns the value of this Long as a double.
float floatValue()
Returns the value of this Long as a float.
int intValue()
Returns the value of this Long as an int.
long longValue()
Returns the value of this Long as a long value.
short shortValue()
Returns the value of this Long as a short.

public class Main {
  public static void main(String[] args) {
    Long longObject = new Long("1234567");
    byte b = longObject.byteValue();
    System.out.println("byte:"+b);

    short s = longObject.shortValue();
    System.out.println("short:"+s);

    int i = longObject.intValue();
    System.out.println("int:"+i);

    float f = longObject.floatValue();
    System.out.println("float"+f);

    double d = longObject.doubleValue();
    System.out.println("double:"+d);

    long l = longObject.longValue();
    System.out.println("long:"+l);
  }
}

The output:


byte:-121
short:-10617
int:1234567
float1234567.0
double:1234567.0
long:1234567
Home 
  Java Book 
    Essential Classes  

Long:
  1. Long class
  2. Constants value from Long class
  3. Constructors from Long
  4. Convert long value to byte, double, float, int, long, short
  5. Decode a string to create long value
  6. Get the long value from a system property
  7. Compare two long values
  8. Parse long value from string
  9. Convert long value to binary, hex and octal format strings
  10. Convert long value to string
  11. Get the sign of the long value
  12. Get the number of zero bits preceding and following
  13. Reverse and rotate a long value