Java String toCharArray() method example.


The toCharArray() method of a String class converts this string to a character array.

Example

Live Demo

import java.lang.*;
public class StringDemo {
   public static void main(String[] args) {
      // converts String value to character array type value
      String str = " Java was developed by James Gosling";
      char retval[] = str.toCharArray();

      // displays the converted value
      System.out.println("Converted value to character array = ");
      System.out.println(retval);
   }
}

Output

Converted value to character array = Java was developed by James Gosling

Updated on: 26-Feb-2020

29 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements