YouTip LogoYouTip

Number Tostring

# Java toString() Method [![Image 3: Java Number Class](#)Java Number Class](#) * * * The toString() method is used to return a string representation of a Number object's value. If the method uses a primitive data type as a parameter, it returns a String object value of the primitive data type. If the method has two parameters, it returns the string representation of the first parameter in the base specified by the second parameter. ### Syntax Taking the String class as an example, the method has the following syntax formats: String toString()static String toString(int i) ### Parameters * **i** -- The integer to be converted. ### Return Value * **toString():** Returns a String object representing the 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)); }} Compiling the above program, the output result is: 512 * * Java Number Class](#)
← Number AbsNumber Equals β†’