Java valueOf() Method
The valueOf() method is used to return the native Number object value of the given argument. The argument can be a native data type, String, etc.
This method is a static method. It can receive 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-- an integer for an Integer object.
s-- a string for an Integer object.
radix-- the radix used when parsing string s, to specify the base number 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 that holds the value extracted from the specified String when parsed using the radix provided by the second argument.
Example
Example
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); // using hexadecimal
System.out.println(x);
System.out.println(c);
System.out.println(a);
System.out.println(b);
}
}
Compile the above program, and the output result is:
9 5.0 80.0 1092
Other Extensions
Java Number Class