Here's how you convert a String to a char array:

String str = "someString"; 
char[] charArray = str.toCharArray();

I'd recommend that you use an IDE when programming, to easily see which methods a class contains (in this case you'd be able to find toCharArray()) and compile errors like the one you have above. You should also familiarize yourself with the documentation, which in this case would be this String documentation.

Also, always post which compile errors you're getting. In this case it was easy to spot, but when it isn't you won't be able to get any answers if you don't include it in the post.

Answer from keyser on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ character-array-in-java
Character Array in Java - GeeksforGeeks
January 22, 2026 - A character array in Java is an array that stores multiple characters (char) in contiguous memory locations. It is useful when you want to manipulate individual characters of a string-like data structure or perform operations such as sorting, searching, or reversing characters.
๐ŸŒ
Edureka
edureka.co โ€บ blog โ€บ character-array-in-java
Char Array In Java | Introduction To Character Arrays In Java | Edureka
July 5, 2024 - Declaration of a char array can be done by using square brackets: ... The square brackets can be placed at the end as well. ... A char array can be initialized by conferring to it a default size.
Discussions

java - How to init char array using char literals? - Stack Overflow
The following statement doesn't work in Java, but works in C: char c[] = "abcdefghijklmn"; What's wrong? Does the char array can only be initialized as following? char c[] = {'a', 'b', 'c', 'd'... More on stackoverflow.com
๐ŸŒ stackoverflow.com
What is the initial values of char arrays?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
๐ŸŒ r/javahelp
9
7
October 15, 2021
Char array vs. char pointer array- specific question (noob learning C)
In C, strings are defined using char * or using a char array: char *name = โ€œZara Aliโ€; or char name[] = โ€œZara Aliโ€; In other words, a string is an array of characters. Your โ€˜namesโ€™ variable, however, is an array of strings. This means that โ€˜namesโ€™ is an array of an array of characters. You can define arrays using square bracket notation or with a *. So โ€˜char *names[]โ€™ is a pointer to an array of chars. If you remove the * then C expects an array of characters and not an array of strings (an array of an array of characters). More on reddit.com
๐ŸŒ r/C_Programming
10
3
February 8, 2023
Initialize a char array?
Am I correct in that the above fails because I'm telling it to put "Mary" in the name[20] element? Technically correct. name[20] is actually out of bounds due to 0-based indexing, so it would be the 21st element in a 20 element array. Either way, you're trying to assign a char* to a char. Is there a way to initialize char name[20] array separately from the declaration without using srtcpy()? Not with a literal. You have to manually copy the bytes. The string literal initialization is a unique exception granted by the standard to char[] objects; normally a string literal is converted to a pointer, but when it appears as an initializer for a char[] it gets copied into the array. More on reddit.com
๐ŸŒ r/cprogramming
18
2
April 23, 2024
People also ask

How do you convert a String to a char array in Java?
To convert a String to a char array, use the toCharArray() method of the String class. This method splits the String into individual characters and stores them in a new char array. It is useful when you need to manipulate or analyze each character separately in char arrays. Once converted, each character can be accessed and modified directly within the char array.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ blog โ€บ software development โ€บ complete guide to char in java: declaration, size, common use cases and more
Exploring Char in Java: Size, Declaration, and Applications
When should I use a char array over a StringBuilder in Java?
Use char arrays when you need to frequently modify characters in place, such as for encryption or parsing. StringBuilder is designed for appending or altering string content efficiently and should be used when constructing larger strings. Char arrays are preferable when working with individual characters and memory optimization is key. For mutable, high-performance operations on characters, char arrays are ideal.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ blog โ€บ software development โ€บ complete guide to char in java: declaration, size, common use cases and more
Exploring Char in Java: Size, Declaration, and Applications
How can you clear sensitive data in a char array in Java?
To clear sensitive data in a char array, use the Arrays.fill() method to overwrite it with a specific value, like '\u0000'. This prevents sensitive information, such as passwords, from lingering in memory after use. Clearing memory ensures better security practices when handling sensitive data. It helps prevent data leaks by explicitly erasing information from memory.
๐ŸŒ
upgrad.com
upgrad.com โ€บ home โ€บ blog โ€บ software development โ€บ complete guide to char in java: declaration, size, common use cases and more
Exploring Char in Java: Size, Declaration, and Applications
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ blog โ€บ software development โ€บ complete guide to char in java: declaration, size, common use cases and more
Exploring Char in Java: Size, Declaration, and Applications
July 7, 2026 - Declare a variable (e.g., element) to hold each value from the array. Use the: operator to specify the array to loop through. The loop automatically iterates through all elements of the array. ... In this example, you store the initials of traditional Indian dance forms in a char in Java array.
๐ŸŒ
Compuhelpindia
compuhelpindia.com โ€บ tutorials โ€บ character-array-in-java.php
Character Array in Java
//Program of character array declaration in Java. public class CharacterArray { public static void main(String[] args) { char charr[]=new char[5]; charr[0]='c'; charr[1]='h'; charr[2]='e'; charr[3]='l'; charr[4]='p'; for(int i=0;i<charr.length;i++) { System.out.print(charr[i]); } ... In the ...
๐ŸŒ
Huda Tutorials
hudatutorials.com โ€บ java โ€บ basics โ€บ java-arrays โ€บ java-char-array
Java char Array - char array in java - Huda Tutorials
July 16, 2021 - The array element index is starting from 0 to n-1 number i.e. if the array has 5 elements then starting index is 0 and ending index is 4. Declaration of a char array can be done by using square brackets.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_string_tochararray.asp
Java String toCharArray() Method
The toCharArray() method returns a new char array representing the contents of the string.
๐ŸŒ
YouTube
youtube.com โ€บ pirple
Java - Declaring Char Arrays | Arrays in Java - YouTube
Learn how to declare and initialize character (char) arrays in Java.In this basic Java tutorial series, we introduce the concepts of "Arrays" and explain how...
Published: April 27, 2019
Views: 7K
๐ŸŒ
Dot Net Perls
dotnetperls.com โ€บ char-array-java
Java - char Array - Dot Net Perls
January 25, 2024 - To begin, char arrays support the array initializer syntax like other arrays. Here we create a new array with 3 elements. Tip Int values, which represent chars in ASCII, can also be used in a char array initializer.
๐ŸŒ
javaspring
javaspring.net โ€บ blog โ€บ java-array-of-characters
Java Array of Characters: A Comprehensive Guide โ€” javaspring.net
This declares a variable charArray of type char[], but it doesn't allocate any memory for the actual characters yet. ... Here, an array of size 5 is created. All the elements are initialized with the default value for char, which is the null character \u0000. ... In this case, the array is initialized with the characters 'h', 'e', 'l', 'l', and 'o' in order. You can access elements in a character array using an index. The index starts from 0.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ string-to-char-array-java-tutorial
String to Char Array Java Tutorial
March 22, 2021 - Length is vowels' length char[] vowelArray = new char[vowels.length()]; // loop to iterate each characters in the 'vowels' string for (int i = 0; i < vowels.length(); i++) { // add each character to the character array vowelArray[i] = ...
๐ŸŒ
Javatpoint
javatpoint.com โ€บ character-array-in-java
Character Array in Java - Javatpoint
Character Array in Java - Character Array in Java with java tutorial, features, history, variables, object, programs, operators, oops concept, array, string, map, math, methods, examples etc.
๐ŸŒ
Tpoint Tech
tpointtech.com โ€บ character-array-in-java
Character Array in Java - Tpoint Tech
May 23, 2026 - Character Array is an array that holds character data types values.
๐ŸŒ
YouTube
youtube.com โ€บ math and science
Learn Java - Exercise 16x - Reading Chars into Character Array - YouTube
Get more lessons like this at http://www.MathTutorDVD.comLearn how to program in java with our online tutorial. We will cover variables, loops, if else bran...
Published: March 30, 2018
Views: 6K
๐ŸŒ
Medium
mvthanoshan.medium.com โ€บ string-to-char-array-java-tutorial-4925e1912cc3
String to Char Array Java Tutorial | by Thanoshan MV | Medium
May 7, 2021 - Length is vowels' length char[] vowelArray = new char[vowels.length()];// loop to iterate each characters in the 'vowels' string for (int i = 0; i < vowels.length(); i++) { // add each character to the character array vowelArray[i] = ...
๐ŸŒ
YouTube
youtube.com โ€บ math and science
Java Tutorial - 16 - Read Characters from a String into a Char Array - YouTube
Get more lessons like this at http://www.MathTutorDVD.com Learn how to program in java with our online tutorial. We will cover variables, loops, if else bran...
Published: March 29, 2018
Views: 34K
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ java-program-to-create-character-array-from-string-objects
Java Program to create Character Array from String Objects
January 14, 2025 - To Create a character array from a string object. we have a method named toCharArray() method which is a member of the String class that belongs to java.lang package. It is used to convert a string into an array of characters.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-declare-a-char-variable-in-Java-and-give-inputs
How to declare a char variable in Java and give inputs - Quora
Answer (1 of 7): Thanks for A2A :) Declaring Variable and giving Inputs in Java can be done in 2 Steps. Step-1 Declaring Variable Syntax to declare any variable in Java is : Datatype variable_name; OR Datatype variable_name = value; For example to create an char and int variable, char c; ...