Convert Long to numeric primitive data types - Java Language Basics

Java examples for Language Basics:long

Description

Convert Long to numeric primitive data types

Demo Code

 
public class Main {
 
  public static void main(String[] args) {
    Long lObj = new Long("10");
    //use byteValue method of Long class to convert it into byte type.
    byte b = lObj.byteValue();
    System.out.println(b);//from  www  . j av a  2  s .com
   
    //use shortValue method of Long class to convert it into short type.
    short s = lObj.shortValue();
    System.out.println(s);
   
    //use intValue method of Long class to convert it into int type.
    int i = lObj.intValue();
    System.out.println(i);
   
    //use floatValue method of Long class to convert it into float type.
    float f = lObj.floatValue();
    System.out.println(f);
 
    //use doubleValue method of Long class to convert it longo double type.
    double d = lObj.doubleValue();
    System.out.println(d);
  }
}
 

Result


Related Tutorials