Java toString() method
The valueOf() method is used to return the Number object value represented by a string.
If the method uses a native data type as a parameter, return the String object value of the native data type.
If the method has two parameters, return the string representation of the first parameter in the base specified by the second parameter.
grammar
Taking the String class as an example, this method has the following syntax formats:
String toString() static String toString(int i)
parameter
i -- The integer to convert.
return value
toString(): Returns a String object representing an Integer value.
toString(int i): Returns a String object representing the specified int.
Example
public class Test{ public static void main(String args[]){ Integer x = 5; System.out.println(x.toString()); System.out.println(Integer.toString(12)); } }
Compile the above program and the output result is:
5 12