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.
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:
array=Welcome to array= for geeks
array=aa array=bb array=cc array=dd
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.