Java valueOf () method
valueOf () method returns the given parameters Number native object values, parameters can be native data types, String and so on.
The method is static. This method can receive two parameters is a string that is a base.
grammar
This method has the following syntax:
static Integer valueOf(int i) static Integer valueOf(String s) static Integer valueOf(String s, int radix)
parameter
i - Integer Integer object.
s - String Integer object.
radix - when parsing a string s use of the base for the specified number of decimal used.
return value
Integer valueOf (int i): Returns a Integer instance representing the specified int value.
Integer valueOf (String s): Integer Returns a String object that holds the specified value.
Integer valueOf (String s, int radix ): Returns an Integer object stored in the base by the second argument to provide a value from the specified String when parsed extracted.
Examples
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); // 使用 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