Convert Char array to String in Java

Java 8Object Oriented ProgrammingProgramming

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
raja
Published on 07-Dec-2018 10:04:02
Advertisements