Easy Tutorial
❮ Java String Contentequals Java File ❯

Java toString() Method

Java Number Class


The toString() method is used to return a String representation of the value of a Number object.

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

If the method has two parameters, it returns a string representation of the first parameter in the radix 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 will output:

5
12

Java Number Class

❮ Java String Contentequals Java File ❯