Convert char to String in java

      No Comments on Convert char to String in java

String can be converted to char in the below ways:

(I.) String.valueOf(char ch)
This returns the string representation of the char argument.

(II.) Character.toString(char ch)
This returns a String object which represents the specified char. The length of the String returned is 1 consisting solely of the specified char.

Example : To Convert char to String in java
package com.masterjavatutorial;
public class TestExample {
   public static void main(String[] args) {
       char ch = 'S';
       String str = String.valueOf(ch);
       System.out.println("str = "+str); 

       String str1 = Character.toString(ch);
       System.out.println("str1 = "+str1);

Output of the above program is as below:

str = S
str1 = S