How to Convert an Integer Into a String in Java

The Java programming language has native support for integers and strings. That support is implemented as classes that handle, among many other methods, the conversions between one type and the other. You can convert an integer value into a string containing the decimal representation of that value in your Java code.

Instructions

    • 1

      Include the following line at the beginning of your Java code:

      import Java.lang.Integer;

    • 2

      Store the value you want to convert into an object of class Integer, as in the following sample code:

      Integer myNumber = 42;

    • 3

      Convert the integer value to a Java String using the Integer.toString() built-in method, as in the following sample code:

      String myNumberAsString = myNumber.toString();

      For the example, string "myNumberAsString" will have value "42".

Related Searches:

References

Comments

Related Ads

Featured