How to convert char to string in Java

4 Answers

0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'z';
        
        String str = String.valueOf(ch);
        
        System.out.println(str);
    }
}




/*
run:

z

*/

 



answered Jun 6, 2021 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'z';
        
        String str = "" + ch;
        
        System.out.println(str);
    }
}




/*
run:

z

*/

 



answered Jun 6, 2021 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'z';
         
        String str = Character.toString(ch);
         
        System.out.println(str);
    }
}
 
 
 
 
/*
run:
 
z
 
*/

 



answered May 27, 2023 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        char ch = 'z';
         
        String str = "%s".formatted(ch);
         
        System.out.println(str);
    }
}

 
 
/*
run:
 
z
 
*/

 



answered Jun 17, 2025 by avibootz

Related questions

1 answer 118 views
118 views asked Nov 22, 2023 by avibootz
2 answers 155 views
155 views asked May 27, 2023 by avibootz
4 answers 545 views
2 answers 248 views
2 answers 263 views
1 answer 251 views
...