R
Rookie
How can I add two char to make a string?
Thank you
Thank you
Millian said:Check out String.valueOf(char) method
To produce a String you could also do like this:
char ch1 = 'a';
char ch2 = 'b';
String str = ch1 + ch2 + "";
Rookie said:How can I add two char to make a string?
Millian Brave said:Sorry, I switched the order of the "". If you do a:
String str = "" + ch1 + ch2... you'll get the result you wanted, "ab" that
is. But I of course agree, this is a dirty way of doing it (implicit cast).
Joona said:Typically, the proper way of making a char into a String would be the
String.valueOf() method instead of "" + char, but I don't see how it
could be used to make *two* chars into *one* String.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.