在Java中将Long转换为数字原始数据类型
假设我们在这里有Long对象。
Long myObj = new Long("9879");现在,如果要将此Long转换为short基本数据类型。为此,请使用内置shortValue()方法-
// converting to short primitive types short shortObj = myObj.shortValue(); System.out.println(shortObj);
以相同的方式将Long转换为另一个数字原始数据类型int。为此,请使用内置intValue()方法-
// converting to int primitive types int intObj = myObj.intValue(); System.out.println(intObj);
以下是一个示例,其中我们将Long转换为数字基本类型short,int,float等-
示例
public class Demo {
public static void main(String[] args) {
Long myObj = new Long("9879");
//转换为数字原始类型
short shortObj = myObj.shortValue();
System.out.println(shortObj);
int intObj = myObj.intValue();
System.out.println(intObj);
float floatObj = myObj.floatValue();
System.out.println(floatObj);
double doubleObj = myObj.doubleValue();
System.out.println(doubleObj);
}
}输出结果
9879 9879 9879.0 9879.0
热门推荐
1 如何训练狗狗不叫
2 训练狗狗不叫
3 训练狗狗随行
4 怎么训练狗狗不叫
7 训练比熊狗狗教程
10 上海狗狗训练
11 怎么训练狗狗上厕所
12 训练狗狗趴下
13 狗狗服从训练
14 训练狗狗拒食
15 训练狗狗笑
16 训练狗狗大便
17 训练狗狗立
18 训练狗狗捡东西