Groovy – xxxValue()

  • Post author:
  • Post category:Groovy
  • Post comments:1 Comment
 parameter

This method takes on the Number as the parameter and returns a primitive type based on the method which is invoked. Following are the list of methods available โˆ’

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

Parameters โˆ’ No parameters required.

Return Value โˆ’ The return value is the primitive type returned depending on the value function which is called.

Example

Following is an example of the usage of the method values.

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

When we run the above program, we will get the following result โˆ’

5.0 
5 
5.0 
5 
5 
5 

Previous Page:-Click Here

This Post Has One Comment

Leave a Reply