how to convert character to string in java code example

Example 1: convert char to string java

char c = 'a';
String s = Character.toString(c);
//s == "a"

Example 2: java convert a string to char[]

String string =  "ABCDEF" ;
 
char[] charsFromString = string.toCharArray(); // { 'A', 'B', 'C', 'D', 'E', 'F' }

Example 3: convert char to string

char c = 'a';
String s = Character.toString(c);

Example 4: char to string jva

char ch = 'a';
String.valueOf(ch);

Example 5: Converting Char to String in java

class CharToStringDemo
{
   public static void main(String args[])
   {
      // Method 1: Using toString() method
      char ch = 'a';
      String str = Character.toString(ch);
      System.out.println("String is: "+str);
 
      // Method 2: Using valueOf() method
      String str2 = String.valueOf(ch);
      System.out.println("String is: "+str2);
   }
}

Example 6: android studio char to string

(char[]).toString();//the lvalue or even rvalue of char[] + toString()
String MyString = new String(MyChars);

Tags: