Convert an int value to String

This code example shows how to convert an int value to a String object.
Actually there are a few possible ways of doing this and three of the most common methods of doing so is presented here.
First we use the static method toString() of the Integer class which takes an integer as argument and returns a String.
The second way of converting from int to String is to instantiate the Integer class and pass the int value to the constructor, and then call the toString() method on the object.
Finally the easiest way of converting from datatype int to String is to simply concatenate the int value to an empty String. That way the value will automatically be converted and appended to the String.

After every conversion the converted value along with the method of which it was converted is printed out to show that the object returned is really an instance of the String class.

When the code is executed the output will be:

Search for more Java info on this site here:
Custom Search

Please type any questions here.