Is there a way to turn a char
into a String
or a String
with one letter into a char
(like how you can turn an int
into a double
and a double
into an int
)? (please link to the relevant documentation if you can).
How do I go about finding something like this that I'm only vaguely aware of in the documentation?
I like to do something like this:
You find the documentation by identifying the classes likely to be involved. Here, candidates are
java.lang.String
andjava.lang.Character
.You should start by familiarizing yourself with:
java.lang
java.util
It also helps to get introduced to the API more slowly through tutorials.
As no one has mentioned, another way to create a String out of a single char:
String.valueOf('X')
will create you a String"X"
"X".charAt(0)
will give you the character'X'
In order to convert string to char