Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

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
Updated on: 2020-06-26T06:24:54+05:30

830 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements