Java Program to Separate the Individual Characters from a String Last Updated : 27 Jan, 2021 Comments Improve Suggest changes Like Article Like Report The string is a sequence of characters including spaces. Objects of String are immutable in java, which means that once an object is created in a string, it's content cannot be changed. In this particular problem statement, we are given to separate each individual characters from the string provided as the input. Therefore, to separate each character from the string, the individual characters are accessed through its index. Examples : Input : string = "GeeksforGeeks" Output: Individual characters from given string : G e e k s f o r G e e k s Input : string = "Characters" Output: Individual characters from given string : C h a r a c t e r sApproach 1: First, define a string.Next, create a for-loop where the loop variable will start from index 0 and end at the length of the given string.Print the character present at every index in order to separate each individual character.For better visualization, separate each individual character by space.Below is the implementation of the above approach : Java // Java Program to Separate the // Individual Characters from a String import java.io.*; public class GFG { public static void main(String[] args) { String string = "GeeksforGeeks"; // Displays individual characters from given string System.out.println( "Individual characters from given string: "); // Iterate through the given string to // display the individual characters for (int i = 0; i < string.length(); i++) { System.out.print(string.charAt(i) + " "); } } } OutputIndividual characters from given string: G e e k s f o r G e e k s Time Complexity: O(n), where n is the length of the string. Approach 2: Define a String.Use the toCharArray method and store the array of Characters returned in a char array.Print separated characters using for-each loop. Below is the implementation of the above approach : Java // Java Implementation of the above approach import java.io.*; class GFG { public static void main(String[] args) { // Initialising String String str = "GeeksForGeeks"; // Converts the string into // char array char[] arr = str.toCharArray(); System.out.println( "Displaying individual characters" + "from given string:"); // Printing the characters using for-each loop for (char e : arr) System.out.print(e + " "); } } OutputDisplaying individual charactersfrom given string: G e e k s F o r G e e k s Time Complexity: O(N)Space Complexity: O(N) Comment More infoAdvertise with us Next Article Java Program to Separate the Individual Characters from a String M mishrapratikshya12 Follow Improve Article Tags : Java Java Programs Java-String-Programs Practice Tags : Java Similar Reads Java Program to Replace Multiple Characters in a String In this program, we will be discussing various methods for replacing multiple characters in String. This can be done using the methods listed below: Using String.replace() methodUsing replaceAll() method Using replaceFirst() method Method 1: Using String.replace() method This method returns a new st 3 min read Java Program to Add Characters to a String We will be discussing out how to add character to a string at particular position in a string in java. It can be interpreted as follows as depicted in the illustration what we are trying to do which is as follows: Illustration: Input: Input custom string = HelloOutput: --> String to be added 'Gee 4 min read Iterate Over the Characters of a String in Java Given string str of length N, the task is to traverse the string and print all the characters of the given string. Illustration: Input : âGeeksforGeeksâ Output : G e e k s f o r G e e k sInput. : âCoderâ Output : C o d e r Methods: Using Naive ApproachUsing String.toCharArray() methodUsing Character 9 min read Java program to count the characters in each word in a given sentence Write a Java program to count the characters in each word in a given sentence? Examples: Input : geeks for geeksOutput :geeks->5for->3geeks->5 Recommended: Please solve it on PRACTICE first, before moving on to the solution. Approach:Here we have to find out number of words in a sentence an 3 min read Java Program to Iterate Over Characters in String Given string str of length N, the task is to traverse the string and print all the characters of the given string using java. Illustration: Input : str = âGeeksforGeeksâ Output : G e e k s f o r G e e k sInput : str = "GfG" Output : G f G Methods: Using for loops(Naive approach)Using iterators (Opti 3 min read Like