Pattern split(CharSequence,int) method in Java with Examples Last Updated : 21 Feb, 2019 Comments Improve Suggest changes Like Article Like Report split(CharSequence, int) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.The array returned contains each substring of the input sequence created by this method. The substrings in the array are in the order in which they occur in the input. If this pattern does not match any subsequence of the input then the resulting array has just one element, namely the input sequence in string form. The limit parameter passed as int help to calculate the number of times the pattern is applied and affects the length of the resulting array. If the limit n is greater than zero then the pattern will be applied at most n - 1 time. If n is non-positive or Zero then the pattern will be applied as many times as possible. Syntax: public String[] split?(CharSequence input, int limit) Parameters: This method accepts two parameter one input which represents character sequence to be split and other limit which represents The result threshold as mentioned in description. Return value: This method returns the array of strings computed by splitting the input around matches of this pattern. Below programs illustrate the split(CharSequence, int) method: Program 1: Java // Java program to demonstrate // Pattern.split(CharSequence) method import java.util.regex.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "geeks"; // create the string // in which you want to search String actualString = "Welcome to geeks for geeks"; // create a Pattern using REGEX Pattern pattern = Pattern.compile(REGEX); // create limit to 2 // so it can applied at most limit - 1 time int limit = 2; // split the text String[] array = pattern.split(actualString, limit); // print array for (int i = 0; i < array.length; i++) { System.out.println("array[" + i + "]=" + array[i]); } } } Output: array[0]=Welcome to array[1]= for geeks Program 2: Java // Java program to demonstrate // Pattern.split(CharSequence) method import java.util.regex.*; public class GFG { public static void main(String[] args) { // create a REGEX String String REGEX = "ee"; // create the string // in which you want to search String actualString = "aaeebbeecceeddee"; // create a Pattern using REGEX Pattern pattern = Pattern.compile(REGEX); // create limit to 2 // so it can applied at most limit - 1 time int limit = 0; // split the text String[] array = pattern.split(actualString, limit); // print array for (int i = 0; i < array.length; i++) { System.out.println("array[" + i + "]=" + array[i]); } } } Output: array[0]=aa array[1]=bb array[2]=cc array[3]=dd Reference: https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html#split(java.lang.CharSequence, int) Comment More infoAdvertise with us Next Article Pattern split(CharSequence,int) method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions java-regular-expression Java-Pattern +1 More Practice Tags : Java Similar Reads Pattern split(CharSequence) method in Java with Examples split(CharSequence) method of a Pattern class used to splits the given char sequence passed as parameter to method around matches of this pattern.This method can split charSequence into an array of String's, using the regular expression used to compile the pattern as a delimiter.so we can say that t 2 min read Pattern matches(String ,CharSequence) method in Java with Examples The matches(String, CharSequence) method of the Pattern class in Java is used to answer whether or not the regular expression matches on the input. To do so we compile the given regular expression and attempts to match the given input against it where both regular expression and input passed as a pa 2 min read Pattern matcher(CharSequence) method in Java with Examples The matcher(CharSequence) method of the Pattern class used to generate a matcher that will helpful to match the given input as parameter to method against this pattern. The Pattern.matcher() method is very helpful when we need to check a pattern against a text a single time, and the default settings 2 min read PrintStream append(CharSequence, int, int) method in Java with Examples The append(CharSequence, int, int) method of PrintStream Class in Java is used to append a specified portion of the specified charSequence on the stream. This charSequence is taken as a parameter. The starting index and ending index to be written are also taken as parameters. Syntax: public void app 2 min read StringWriter append(CharSequence, int, int) method in Java with Examples The append(CharSequence, int, int) method of StringWriter Class in Java is used to append a specified portion of the specified charSequence on the writer. This charSequence is taken as a parameter. The starting index and ending index to be written are also taken as parameters. Syntax: public void ap 2 min read Like