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 Java Program to Check Whether the String Consists of Special Characters In Java, special characters refer to symbols other than letters and digits, such as @, #, !, etc. To check whether the String consists of special characters, there are multiple ways, including using the Character class, regular expressions, or simple string checks.Example:In this example, we will us 4 min read How to find the first and last character of a string in Java Given a string str, the task is to print the first and the last character of the string. Examples: Input: str = "GeeksForGeeks" Output: First: G Last: s Explanation: The first character of the given string is 'G' and the last character of given string is 's'. Input: str = "Java" Output: First: J Las 3 min read Java Program to Replace All Line Breaks from Strings Given a string, write a Java program to replace all line breaks from the given String. Examples Input - Geeks For Geeks Output - Geeks For Geeks Line Break: A line break ("\n") is a single character that defines the line change. In order to replace all line breaks from strings replace() function can 2 min read Java program to swap first and last characters of words in a sentence Write a Java Program to Swap first and last character of words in a Sentence as mentioned in the example? Examples: Input : geeks for geeks Output :seekg rof seekg Approach:As mentioned in the example we have to replace first and last character of word and keep rest of the alphabets as it is. First 2 min read 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 Like