In this post we will write a program in Java to convert character array to string. Let’s first understand the difference between them. The only difference between them is the “\O”, a string ends with this special character while a character array does not. Below is the program to convert character array t0 string:
/* Java Char Array To String Example This Java char array to String example shows how to convert char array to String in Java. */ public class CharArrayToStringExample { public static void main(String args[]){ //char array char[] charArray = new char[]{'J','a','v','a'}; /* * To convert char array to String in Java, use * String(Char[] ch) constructor of Java String class. */ String str = new String(charArray); System.out.println("Char array converted to String: " + str); } } /* Output of above given char array to String example would be Char array converted to String: Java */