Java valueOf() Method
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
-
i -- the integer of the Integer object.
-
s -- the string of the Integer object.
-
radix -- the radix used when parsing the string s, specifying the radix to use.
Return Value
-
Integer valueOf(int i):Returns an Integer instance representing the specified int value.
-
Integer valueOf(String s):Returns an Integer object holding the value of the specified String.
-
Integer valueOf(String s, int radix): Returns an Integer object holding the value extracted from the specified String when parsed with the radix supplied by the second argument.
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
The Java Number class