Java toString() Method

Java Number类Java Number Class


The toString() method is used to return the value of a Number object represented as a string.

If the method uses a primitive data type as a parameter, it returns the String object value of the primitive data type.

If the method has two parameters, it returns the string representation of the first parameter expressed in the radix specified by the second parameter.

Syntax

Taking the String class as an example, this 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)); 
    }
}

Compile the above program, the output result is:

5
12

Java Number类Java Number Class

Other Extensions