Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java xxxValue() Method

Java xxxValue() Method

Java Number ClassThe Java Number class


The xxxValue() method converts a Number object into xxx data type value and returns it.

The related methods are:

Type Method and description
byte

byteValue() :

Returns the specified value as a byte.

abstract double

doubleValue() :

Returns the specified value as a double.

abstract float

floatValue() :

Returns the specified value as a float.

abstract int

intValue() :

Returns the specified value as an int.

abstract long

longValue() :

Returns the specified value as a long.

short

shortValue() :

Returns the specified value as a short.

Parameters

None of the above functions accepts any arguments.

Return Value

Converts to xxx the value represented by the object after conversion to that type.

Example

Test.java file

public

class

Test

{

public

static

void

main

(

String

args

[

]

)

{

Integer

x

=

5

;

//

Returns a byte primitive data type

System

.

out

.

println

(

x

.

byteValue

(

)

)

;

//

Returns a double primitive data type

System

.

out

.

println

(

x

.

doubleValue

(

)

)

;

//

Returns a long primitive data type

System

.

out

.

println

(

x

.

longValue

(

)

)

;

}

}

Compile the above program; the output is:



5

5.0

5


Java Number ClassThe Java Number class