Convert a String to Character Array in Java Last Updated : 04 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report Converting a string to a character array is a common operation in Java. We convert string to char array in Java mostly for string manipulation, iteration, or other processing of characters. In this article, we will learn various ways to convert a string into a character array in Java with examples.Example:The toCharArray() method is the simplest and most efficient way to convert a string to a character array. Java // Java Program to Convert a String to a Character Array // using toCharArray() import java.util.Arrays; public class StringToCharArray { public static void main(String[] args) { // Defining a string String s = "Java"; // Converting the string to a character array char[] c = s.toCharArray(); System.out.println("" + Arrays.toString(c)); } } Output[J, a, v, a] Note: We can use the charAt() method, that returns the character at the specified index of a string., where the index is zero-based.Other Ways to Convert a String to Character ArrayUsing Streams (Java 8+)Java Streams provide a functional way to convert a string into characters and process them for modern Java applications. Java // Java Program to Convert String to Character Array // Using Streams import java.util.Arrays; public class StringToCharArray { public static void main(String[] args) { // Defining a string String s = "Java"; // Converting string to character array using streams char[] ch = s.chars() .mapToObj(c -> (char) c) .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append) .toString() .toCharArray(); // Convert StringBuilder to char array System.out.println(Arrays.toString(ch)); } } Output[J, a, v, a] Explanation:s.chars(): This converts the string into an IntStream of character codes.mapToObj(c -> (char) c): This maps each integer character code to a Character object.collect(...): It collects the characters into a StringBuilder.toString().toCharArray(): It converts the StringBuilder to a string, then to a char[] array.Using String.split()This is not an efficient way to convert string to character array. But we can split the string into individual characters using the split() method.Example: Java // Java Program to Convert String to Character Array // Using split() import java.util.Arrays; public class StringToCharArray { public static void main(String[] args) { // Defining a string String s = "Java"; // Splitting the string into individual characters String[] ch = s.split(""); System.out.println("" + Arrays.toString(ch)); } } Output[J, a, v, a] When to Use Which MethodtoCharArray(): For simplicity and efficient way.Streams: For modern functional programming.split(): Not an efficient way, do not prefer to use. Convert a String to Character Array in Java Comment More infoAdvertise with us Next Article Convert a String to a ByteBuffer in Java S Shivi_Bhaiya Follow Improve Article Tags : Java Java Programs Java-String-Programs Practice Tags : Java Similar Reads How to Convert a String to a Character in Java? String and char are fundamental and most commonly used datatypes in Java. A String is not a primitive data type like char. To convert a String to char in Java, we have to perform character-based operations or have to process individual characters.In this article, we will learn how to convert a Strin 3 min read Convert a String to a ByteBuffer in Java In Java, ByteBuffer can be used to perform operations at the Byte level one more thing is this class provides different types of methods for reading writing, and manipulating bytes in a structured way only. In this article, we will learn about String to ByteBuffer in Java. Java Program to Convert St 4 min read How to Convert a String to ArrayList in Java? Converting String to ArrayList means each character of the string is added as a separator character element in the ArrayList. Example: Input: 0001 Output: 0 0 0 1 Input: Geeks Output: G e e k s We can easily convert String to ArrayList in Java using the split() method and regular expression. Paramet 1 min read How to Convert JSON Array to String Array in Java? JSON stands for JavaScript Object Notation. It is one of the widely used formats to exchange data by web applications. JSON arrays are almost the same as arrays in JavaScript. They can be understood as a collection of data (strings, numbers, booleans) in an indexed manner. Given a JSON array, we wil 3 min read How to Convert Char to String in Java? In this article, we will learn how to Convert Char to String in Java. If we have a char value like 'G' and we want to convert it into an equivalent String like "G" then we can do this by using any of the following three listed methods in Java. Using toString() method of Character classUsing valueOf( 5 min read Convert String to Stream of Chars in Java The StringReader class from the java.io package in Java can be used to convert a String to a character stream. When you need to read characters from a string as though it were an input stream, the StringReader class can be helpful in creating a character stream from a string. In this article, we wil 2 min read Like