Question:
How do you convert char array to String in Java?
Answer:
Use String(array) or String.valueOf(array)
Code:
public class CharArrayToString { public static void main(String[] args) { char[] array = new char[] {'a', 'b', 'c', 'A', 'B', 'C', '1', '2', '3'}; String str1 = new String(array); System.out.println("str1 : " + str1); String str2; str2 = String.valueOf(array); System.out.println("str2 : " + str2); } }
Output:
$ java CharArrayToString str1 : abcABC123 str2 : abcABC123