In this example we will show two ways to convert an array of characters into a string in Java.
Source Code
package com.beginner.examples;
public class CharArrayToString {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
char[] chs = {'h', 'e', 'l', 'l', 'o'};
String str = new String(chs);
System.out.println(str);
String str1 = String.valueOf(chs);
System.out.println(str1);
}
}
Output:
hello
hello