Java program to convert a character array to string

Java Programming Java8Object Oriented Programming

The String class provides a constructor which accepts an array of characters and creates a String object.

To convert a character array to string simply pass this array to the constructor of the String class.

Example

Live Demo

public class CharArrayToString {
   public static void main(String args[]){
      char[] charArray = {'h', 'e', 'l', 'l', 'o'};
      String str = new String(charArray);
      System.out.println(str);
   }
}

Output

hello
raja
Published on 26-Apr-2018 06:29:54
Advertisements