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

Java valueOf() Method

Java valueOf() Method

Java Number ClassThe Java Number class


The valueOf() method returns the native Number object value of the given argument; the argument can be a primitive data type, a String, and so on.

This method is static. It can accept two arguments: one is a string and the other is a radix.

Syntax

This method has the following syntax formats:



static Integer valueOf(int i)

static Integer valueOf(String s)

static Integer valueOf(String s, int radix)

Parameters

Return Value

Example

Example

public

class

Test

{

public

static

void

main

(

String

args

[

]

)

{

               

Integer

x

=

Integer

.

valueOf

(

9

)

;

               

Double

c

=

Double

.

valueOf

(

5

)

;

               

Float

a

=

Float

.

valueOf

(

"80"

)

;

             

               

Integer

b

=

Integer

.

valueOf

(

"444"

,

16

)

;

 

// use radix 16

               

System

.

out

.

println

(

x

)

;

               

System

.

out

.

println

(

c

)

;

               

System

.

out

.

println

(

a

)

;

               

System

.

out

.

println

(

b

)

;

       

}

}

Compile the above program; the output is:



9

5.0

80.0

1092


Java Number ClassThe Java Number class