CodesJava

Easy learning with example program codes

Char array to string in java

Java convert char array to string using String constructor.

package com.codesjava;
 
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.codesjava;
 
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.

Please follow and like us:
error
Posted in Java   








Copyright © 2019 CodesJava DMCA.com Protection Status