Tutorialspoint examples

Learn java tutorial with examples for beginners online

Convert char array to string java program


Java convert char array to string using String constructor.

package com.tutorialspointexamples;
 
public class CharArrayToString {
  public static void main(String args[]){
      char[] ch = {'J', 'a', 'i'};
      String str = new String(ch);
      System.out.println(str);
  }
}

Output:

Jai

Download this example.

Java convert char array to string using String.valueOf() method

package com.tutorialspointexamples;
 
public class CharArrayToString {
  public static void main(String args[]){
      char[] ch = {'J', 'a', 'i'};
      String str = String.valueOf(ch);
      System.out.println(str);
  }
}

Output:

Jai

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status