Java toString() Method
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
-
i -- the integer to convert.
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 is:
5
12
The Java Number class