Convert Char array to String in Java



The valueOf() method is used in Java to convert char array to string.

Here is our char array.

// char array
char[] c = {'p','q','r','s','t','u','v'};

To convert it to string, use the valueOf() method.

String str = String.valueOf(c);

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      // char array
      char[] c = {'p','q','r','s','t','u','v'};
      // converting to string
      String str = String.valueOf(c);
      System.out.println("String: "+str);
   }
}

Output

String: pqrstuv
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements