Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java toString() Method

Java toString() Method

Java Number ClassThe Java Number class


The toString() method returns the value of a Number object as a string.

If the method takes a primitive data type as its argument, it returns the String object value of that primitive data type.

If the method has two arguments, it returns the string representation of the first argument in the radix specified by the second argument.

Syntax

Taking the String class as an example, this method has the following syntax formats:



String toString()

static String toString(int i)

Parameters

Return Value

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 is:



5

12


Java Number ClassThe Java Number class