The split(String regex, int limit) method is same as split(String, regex) method but the only difference here is that you can limit the number of elements in the resultant Array.
Method Definition: String[] split(String regex, int limit)
Return Type: It returns a String array where, the number of elements in the Array are specified and the last element of the array is the part that is left in the stated string.
Example: 1#
// Scala program of split() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying split method val result = "PfsoQmsoRcsoGfGkso".split(".so", 3) for ( m1 <-result ) { // Displays output println(m1) } } } |
P Q RcsoGfGkso
So, here we have three elements in the resultant Array and the last element contains the remaining part of the string which is left after splitting the second element of an Array.
Example: 2#
// Scala program of split() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying split method val result = "NidhifsoSinghmsoAcso".split(".so", 2) for ( m1 <-result ) { // Displays output println(m1) } } } |
Nidhi SinghmsoAcso
Recommended Posts:
- Scala String regionMatches(int toffset, String other, int offset, int len) method with example
- Scala Int to(end: int, step: int) method with example
- Scala Int until(end: Int, step: Int) method with example
- Scala String substring(int beginIndex, int endIndex) method with example
- Scala String indexOf(int ch, int fromIndex) method with example
- Scala String lastIndexOf(int ch, int fromIndex)() method with example
- Scala Int /(x: Int) method with example
- Scala Int !=(x: Int) method with example
- Scala Int %(x: Int) method with example
- Scala Int &(x: Int) method with example
- Scala Int *(x: Int) method with example
- Scala Int +(x: Int) method with example
- Scala Int -(x: Int) method with example
- Scala Int <(x: Int) method with example
- Scala Int <=(x: Int) method with example
- Scala Int ==(x: Int) method with example
- Scala Int <<(x: Int) method with example
- Scala Int >(x: Int) method with example
- Scala Int >=(x: Int) method with example
- Scala Int >>(x: Int) method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

