Java shortValue()方法

shortValue()方法

Java中的Number包装类内置了shortValue()的方法,shortValue()的主要作用是将Byte、Integer、Short、Double、Long、Float等包装类对象转为short这一基本数据类型的值。shortValue()语法如下:

NumberObj.shortValue()

shortValue()方法实例代码

public class test {
    public static void main(String[] args) {
        Integer z = 150;
        short a = z.shortValue();
        Double y = 33.6;
        short b = y.shortValue();
        Long x = 3660L;
        short c = x.shortValue();
        Short w = 2;
        short d = w.shortValue();
        Float v = 6.21f;
        short e = v.shortValue();
        
        System.out.println("a="+a+",b="+b+",c="+c+",d="+d+",e="+e);
    }

}

免责声明:内容仅供参考,不保证正确性!


全栈后端 / Java教程 :









Copyright © 2022-2024 笨鸟工具 x1y1z1.com All Rights Reserved.