Convert Character Array to String Example Java Program


To convert a character array to string. This can be achieved by two methods.


  • By initializing a new instance of string using character array like 'new String(character_array)'
  • By using a default method in String package like 'String.valueOf(character_array)'


new String(character_array)

Example Program

public class CharacterArrayToString {
    public static void main(String[] args) {
        char[] array = new char[]{'L','I','T','T','L','E','D','R','O','P','S'};
        System.out.println("Converting character array to string");
        String methodOne = new String(array);
        System.out.println("Result by method 1 : "+methodOne);
        String methodTwo = String.valueOf(array);
        System.out.println("Result by method 2 : "+methodTwo);

Sample Output

Converting character array to string
Result by method 1 : LITTLEDROPS
Result by method 2 : LITTLEDROPS