Java convert char array to string using String constructor.
package com.w3spoint;
public class CharArrayToString {
public static void main(String args[]){
char[] ch = {'J', 'a', 'i'};
String str = new String(ch);
System.out.println(str);
}
} |
package com.w3spoint; public class CharArrayToString {
public static void main(String args[]){
char[] ch = {'J', 'a', 'i'};
String str = new String(ch);
System.out.println(str);
}
}
Output:
Download this example.
Java convert char array to string using String.valueOf() method
package com.w3spoint;
public class CharArrayToString {
public static void main(String args[]){
char[] ch = {'J', 'a', 'i'};
String str = String.valueOf(ch);
System.out.println(str);
}
} |
package com.w3spoint; public class CharArrayToString {
public static void main(String args[]){
char[] ch = {'J', 'a', 'i'};
String str = String.valueOf(ch);
System.out.println(str);
}
}
Output:
Download this example.