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()`

The inline compiler is disabled on small screens so the reference page stays stable. Use the header compiler button for mobile testing.

Advertisement