Hey, how do I caonvert a character to a String? The toString() method isn't working like this...
String s = c.toString();
Printable View
Hey, how do I caonvert a character to a String? The toString() method isn't working like this...
String s = c.toString();
String str = (new Character( ch )).toString();
or (better)
String str = Character.toString( ch );
Extra explanation: only objects have a toString(). A character (char) is not an object but a primitive.
You can use the valueOf() method in the String class. Or take advantage of String concatenation:
Code:"" + c;
Thanks guys, you're right, I just had to wrap it in the Character object, valueOf() also worked.