Total Pageviews

2015/03/04

How to convert a char to a string in Java

Problem
I have a char and I need a String.
1
2
char c = 'a';
String s = c;

But eclipse complain it has compile error : Type mismatch: cannot convert from char to String

Solution
String concatenation can fix this type mismatch error:

1
2
char c = 'a';
String s = "" + c;


Reference
[1] http://stackoverflow.com/questions/8172420/how-to-convert-a-char-to-a-string-in-java

No comments: