Introduction
Java's String class provides several methods for manipulating text, and one such method is toCharArray(). This method allows you to convert a string into an array of characters. It can be useful when you need to process or manipulate individual characters from a string.

In this article, we will discuss how to use the toCharArray() method in Java, covering its syntax, parameters, return value, and providing examples for better understanding.
String toCharArray() Function in Java
The toCharArray() method in Java is a built-in function that converts a string to a sequence of characters. The length of the output array is equal to the length of the String, and the chars in Array are in the same order as the characters in the String.
Syntax
The syntax of string toCharArray() method is given below:
string.toCharArray()
The string is a String class object in this case.
Parameter
The toCharArray() method doesn't take any parameters.
Return Value
It returns a newly allocated character array.
Internal Implementation
public char[] toCharArray() {
char output[] = new char[value.length];
System.arraycopy(value, 0, output, 0, value.length);
return output;
}
Examples
Input: hello !
Output: hello !