java tutorial - How to Convert Char Array To String in java - java programming - learn java - java basics - java for beginners



 chararr to str

Learn Java - Java tutorial - chararr to str - Java examples - Java programs

Char Array To String

  • The String is a class whereas the char is a primitive data type.
  • You can use String.valueOf(char c) or else Character.toString(char c) to convert char into string.
  • So it’s better to use String class function to convert char into String. Arrays.toString method is used to print the char array.
  • Arrays is a utility class in java that provides many useful methods to work with array.

sample code:

public class Chararr_to_Str {
    public static void main(String args[]){
        char[] chararr = new char[]{'w','i','k','i','t','e','c','h','y'};
        String str = new String(chararr);
        System.out.println("converted Char array to String: " + str);
    }
}

Output:

converted Char array to String:
                              wikitechy

Related Searches to How to Convert Char Array To String in java