How to Convert Char Array to String in Java


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
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments