Java Program to Convert String to String Array Using Regular Expression Last Updated : 02 Jun, 2022 Comments Improve Suggest changes Like Article Like Report Regular Expressions or Regex (in short) is an API for defining String patterns that can be used for searching, manipulating, and editing a string in Java. Email validation and passwords are few areas of strings where Regex is widely used to define the constraints. Regular Expressions are provided under java. util.regex package. This consists of 3 classes and 1 interface. Hence, in short, we can conclude, java's regular expression is used to find, match, and extract data from character sequences. Approach: We can convert String to String Array using the split method of the String class and Regular Expression. First, we split the string with the help of Regular ExpressionNow store this in an array.Print and display on the console Methods: Using split() method onlyUsing '?!^' regular expression along with split() method Method 1: Using split() method only Example: Java // Java program to demonstrate how to convert String to // String Array using Regular Expression in Java // Importing all classes from // java.util package import java.util.*; // Importing Matcher class that searches through a text for // multiple occurrences of a regular expression import java.util.regex.Matcher; // Importing Pattern class import java.util.regex.Pattern; // Importing Pattern class to compile regex // Class class GFG { // Main driver method public static void main(String[] args) { // Random string input String gfg = "Welcome, to, GFG"; // Splitting of string into characters and // storing it in an array string // separated by comma in between characters String[] str = gfg.split(","); // Traversing the above array // using for each loop for (String s : str) { // Print the characters of the array // formed from input string System.out.println(s); } } } OutputWelcome to GFG Method 2: Using '?!^' regular expression along with split() method Approach: With the split method, we will use the ?!^ Regular Expression that split the string. And extract data of character sequence. ?! — It means a negative look ahead.^ — It is the start of the string. Example: Java // Java program to demonstrate how to convert String to // String Array using Regular Expression in Java // Importing all classes from // java.util package import java.util.*; // Importing Matcher and Pattern classes from // java.util.regex package because // Matcher Class searches through a text for // multiple occurrences of a regular expression import java.util.regex.Matcher; // Pattern Class to compile regex import java.util.regex.Pattern; // Class class GFG { // Main driver method public static void main(String[] args) { // Random input string String gfg = "Welcome, to, GFG"; // Split the above input string // using split() method and // store the input string elements as an array String[] str = gfg.split("(?!^)"); // Print all the elements of an array System.out.println(Arrays.toString(str)); } } Output[W, e, l, c, o, m, e, ,, , t, o, ,, , G, F, G] Comment More infoAdvertise with us Next Article Java Program to Convert String to String Array Using Regular Expression N nikhilchhipa9 Follow Improve Article Tags : Java Java Programs Java-String-Programs Practice Tags : Java Similar Reads Java Program to Convert String to String Array Given a String, the task is to convert the string into an Array of Strings in Java. It is illustrated in the below illustration which is as follows: Illustration: Input: String : "Geeks for Geeks" Output: String[]: [Geeks for Geeks]Input: String : "A computer science portal" Output: String[] : [A co 6 min read Java Program to Convert String to Char Stream Without Using Stream Char stream defines the array of characters. In this article, we will learn the different types of methods for converting a String into a char stream in Java without using Stream. Let us see some methods one by one. ExamplesInput: String = HelloGeeksOutput: [H, e, l, l, o, G, e, e, k, s] Input: Stri 4 min read Java Program to Convert String to Byte Array Using getBytes() Method In Java, strings are objects that are backed internally by a char array. So to convert a string to a byte array, we need a getByte() method. It is the easiest way to convert a string to a byte array. This method converts the given string to a sequence of bytes using the platform's default charset an 2 min read Java Program to Convert String to Integer Array In Java, we cannot directly perform numeric operations on a String representing numbers. To handle numeric values, we first need to convert the string into an integer array. In this article, we will discuss different methods for converting a numeric string to an integer array in Java.Example:Below i 3 min read Java Program to Extract an HTML Tag from a String using RegEx In this article, we will find/extract an HTML tag from a string with help of regular expressions. The Regular Expression Regex or Rational Expression is simply a character sequence that specifies a search pattern in a particular text. It can contain a single character or it can have a complex sequen 3 min read How to Split Strings Using Regular Expressions in Java? Split a String while passing a regular expression (Regex) in the argument and a single String will split based on (Regex), as a result, we can store the string on the Array of strings. In this article, we will learn how to split the string based on the given regular expression. Example of Split Stri 2 min read Java Program to Extract a Single Quote Enclosed String From a Larger String using Regex Problem Statement: Given a String extract the substring enclosed in single quotes (') using Java Regex. Java regex is an API for pattern matching with regular expression. 'java.util.regex' is a class used for CharSequence< interface in order to support matching against characters from a wide vari 3 min read Convert a List of String to a comma separated String in Java Given a List of String, the task is to convert the List to a comma separated String in Java. Examples: Input: List<String> = ["Geeks", "ForGeeks", "GeeksForGeeks"] Output: "Geeks, For, Geeks" Input: List<String> = ["G", "e", "e", "k", "s"] Output: "G, e, e, k, s" Approach: This can be ac 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 Java Program to Search a Particular Word in a String Using Regex In Java string manipulation, searching for specific words is a fundamental task. Regular expressions (regex) offer a powerful and flexible approach to achieve this search. It matches the patterns simply by comparing substrings. In this article, we will learn how to search for a particular word in a 3 min read Like