You are on page 1of 1

JAVA - TOSTRING() METHOD

http://www.tutorialspoint.com/java/number_tostring.htm

Copyright tutorials point.com

Descript ion:
The met hod is used t o get a St ring object represent ing t he value of t he Number Object .
If t he met hod t akes a primit ive dat a t ype as an argument , t hen t he St ring object represent ing t he
primit ive dat a t ype value is ret urn.
If t he met hod t akes t wo argument s, t hen a St ring represent at ion of t he first argument in t he radix
specified by t he second argument will be ret urned.

Synt ax:
All t he variant of t his met hod are given below:
String toString()
static String toString(int i)

Paramet ers:
Here is t he det ail of paramet ers:
i -- An int for which st ring represent at ion would be ret urned.

Ret urn Value:


to String(): This ret urns a St ring object represent ing t he value of this Int eger.
to String(int i): This ret urns a St ring object represent ing t he specified int eger.

Example:
public class Test{
public static void main(String args[]){
Integer x = 5;
System.out.println(x.toString());
System.out.println(Integer.toString(12));
}
}

This produces t he following result :


5
12

You might also like