集册 Java实例教程 将Long转换为数字原始数据类型

将Long转换为数字原始数据类型

欢马劈雪     最近更新时间:2020-01-02 10:19:05

636
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将Long转换为数字原始数据类型

 

public class Main {
/*
N o w  J a v a  .   c o m 提供
*/

 

  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);

   

    //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);

   
   /*
   NowJava.com - 时  代  Java 提供
   */

    //use floatValue method of Long class to convert it into float type.

    float f = lObj.floatValue();

    System.out.println(f);

展开阅读全文