Conversion from char
to String
can be accomplished by using the "+" (concatenation) operator described previously. Concatenating any char
with an empty string (String
of length zero) results in a string that consists of that char
. The java notation for an empty string is two consecutive double quotation marks. For example, the following expression
"" + 'X';
evaluates to a String
of length 1, consisting of the letter "X"
// charVar is a variable of type char
// stringVar is a variable of type String
stringVar = "" + charVar;
The execution of this instruction assigns to stringVar
a String
object that consist of the single character from charVar
.