Char array to string in java

Java convert char array to string using String constructor.

package com.w3schools;

public class CharArrayToString {
  public static void main(String args[]){
      char[] ch = {'J', 'a', 'i'};
      String str = new String(ch);
      System.out.println(str);
  }
}

Output:

Jai

Download this example.

Java convert char array to string using String.valueOf() method

package com.w3schools;

public class CharArrayToString {
  public static void main(String args[]){
      char[] ch = {'J', 'a', 'i'};
      String str = String.valueOf(ch);
      System.out.println(str);
  }
}

Output:

Jai

Download this example.