xxxValue()

优质
小牛编辑
125浏览
2023-12-01

此方法将Number作为参数,并根据调用的方法返回基本类型。 以下是可用的方法列表 -

byte byteValue() 
short shortValue() 
int intValue() 
long longValue() 
float floatValue() 
double doubleValue()

Parameters - 无需参数。

Return Value - 返回值是根据调用的值函数返回的基本类型。

例子 (Example)

以下是方法值的使用示例。

class Example { 
   static void main(String[] args) {  
      Integer x = 5; 
      // Converting the number to double primitive type
      println(x.doubleValue()); 
      // Converting the number to byte primitive type 
      println(x.byteValue()); 
      // Converting the number to float primitive type 
      println(x.floatValue());
      // Converting the number to long primitive type 
      println(x.longValue()); 
      // Converting the number to short primitive type 
      println(x.shortValue()); 
      // Converting the number to int primitive type 
      println(x.intValue());  
   } 
}

当我们运行上述程序时,我们将得到以下结果 -

5.0 
5 
5.0 
5 
5 
5