JRJC - How To Convert Integers to Strings

I suppose the "proper" way to convert an integer to a string is using the String.valueOf() method, although I don't find this to be straightforward:

    int x = 222 ;
    String s = String.valueOf( x );  // s is now set to "222"

If you know that the string will be used in string concatenation, you can take advantage of a conversion that Java will do for you:

    int x = 6 ;
    System.out.println("I am " + x + " years old.");

For more information, please visit my java site.

And for a change of pace, you can visit my permaculture site.

© 2000 paul wheaton