Reference

Java reference, syntax, and runnable examples in one place.

Search Java methods, scan syntax and return types, read plain-English explanations, and run selected examples without leaving the reference flow.

Results

138 items match your filters.

String Methods

toCharArray()

Converts the string into a new character array.

Category

String Methods

Best use

Use this entry when you need the syntax, return type, and a runnable example quickly.

Syntax

char[] toCharArray()

Returns

char[]

Example

String str = "Hello";
char[] chars = str.toCharArray();
for (char c : chars) {
    System.out.println(c);
}

Live example

Run and edit `toCharArray()`

This runner wraps shorter snippets in a `Main` class automatically so you can test the example on the page.

Loading...

Output

(run the example to see output here)

Advertisement