Java - String toCharArray() Method
The Java string toCharArray() method returns a character array containing all characters of the string.
Syntax
public char[] toCharArray()
Parameters
No parameter is required.
Return Value
Returns a character array containing all characters of the string.
Example:
In the example below, toCharArray() method returns a character array containing all characters of the given string.
import java.lang.*; public class MyClass { public static void main(String[] args) { String MyString = "HELLO"; char[] Arr = MyString.toCharArray(); for(int i = 0; i < Arr.length; i++) System.out.print(Arr[i] + " "); } }
The output of the above code will be:
H E L L O
❮ Java.lang - String