Java中的数字包装器类及其方法是什么?
java.lang包的Number类(抽象)表示可转换为原始类型byte,double,float,int,long和short的数值。
以下是java.lang包的Number类提供的方法。
字节byteValue()
此方法以字节为单位返回指定数字的值。
抽象双doubleValue()
此方法以双精度值形式返回指定数字的值。
抽象浮点数floatValue()
此方法以浮点数形式返回指定数字的值。
抽象整数intValue()
此方法以int形式返回指定数字的值。
抽象长longValue()
此方法以long形式返回指定数字的值。
短shortValue()
此方法以short形式返回指定数字的值。
示例
public class NumberClassExample {
public static void main(String args[]){
Number num = new Integer("25");
System.out.println("Float value of the number: "+num.floatValue());
System.out.println("Double value of the number: "+num.doubleValue());
System.out.println("Long value of the number: "+num.longValue());
System.out.println("Byte value of the number: "+num.byteValue());
System.out.println("Double value of the number: "+num.doubleValue());
System.out.println("Short value of the number: "+num.shortValue());
}
}输出结果
Float value of the number: 25.0 Double value of the number: 25.0 Long value of the number: 25 Byte value of the number: 25 Double value of the number: 25.0 Short value of the number: 25
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短