Popular Tutorials
Start Learning JavaCertification Courses
Created with over a decade of experience and thousands of feedback.
Python online compiler
JavaScript online compiler
SQL online compiler
Java online compiler
HTML online compiler
C online compiler
C++ online compiler
C# online compiler
PHP online compiler
Swift online compiler
Kotlin online compiler
TypeScript online compiler
Go online compiler
Rust online compiler
Scala online compiler
Dart online compiler
R online compiler
Ruby online compiler
Java String toCharArray()
The Java String toCharArray() method converts the string to a char array and returns it.
The syntax of the toCharArray() method is:
string.toCharArray()
Here, string is an object of the String class.
toCharArray() Parameters
The toCharArray() method doesn't take any parameters.
toCharArray() Return Value
- returns a char array
Example: Java String toCharArray()
class Main {
public static void main(String[] args) {
String str = "Java Programming";
// creating a char array
char[] result;
result = str.toCharArray();
System.out.println(result); // Java Programming
}
}
Here, the length of the char array result will be equal to the length of the string str.
Also Read:
Did you find this article helpful?