Java Example – Char Array To String




Java Tutorial for Beginners
Java Tutorial for Beginners

In this Java Example we will see how to convert char array to String. The example below shows how to convert char array to String in Java.

/**
 *  Created by codebind.com.
 */
public class CharArrayToString {

    public static void main(String args[]){

        //char array
        char[] charArray = new char[]{'H','E','L','L','O'};

                /*
                 * 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("converted Char array to String: " + str);
    }
}

/**
 * Output
 converted Char array to String: HELLO
 */

 





Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*