Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (10.2k points)

I have a char and I need a String. How do I convert from one to the other?

1 Answer

0 votes
by (46k points)

Using String.valueOf() method:

Syntax:

char c='S';  

String s=String.valueOf(c);  

Example:

public class CharToStringExample1{  

public static void main(String args[]){  

char c='S';  

String s=String.valueOf(c);  

System.out.println("String is: "+s);  

}}  

Using Character.toString() method:

Here's a simple code to change char to String in Java using Character.toString() method:

Input:

public class CharToStringExample2{  

public static void main(String args[]){  

char c='N';    

String s=Character.toString(c);  

System.out.println("String is: "+s);    

}}  

Output:

String is: N

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer

Browse Categories

...