Scala String split(String regex, int limit) method with example Last Updated : 29 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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 // 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) } } } Output: 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 // 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) } } } Output: Nidhi SinghmsoAcso Comment More infoAdvertise with us Next Article Scala String split(String regex, int limit) method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Scala-Strings Similar Reads Scala String lastIndexOf(String str) method with example The lastIndexOf(String str) method is utilized to return the index of the last appearance of the sub-string we specify in the argument from the stated string. Method Definition: int lastIndexOf(String str) Return Type: It returns the index of the last appearance of the sub-string specified in the ar 1 min read Scala String substring() method with example The substring() method is utilized to find the sub-string from the stated String which starts from the index specified. Method Definition: String substring(int beginIndex) Return Type: It returns the content from the given String Which starts from the index we specify. Example: 1# Scala // Scala pro 1 min read Scala String lastIndexOf(String str, int fromIndex) method with example The lastIndexOf(String str, int fromIndex) method is utilized to return the index of the last appearance of the sub-string we specify in the argument from the index specified from right to left from the stated string. Method Definition: int lastIndexOf(String str, int fromIndex) Return Type: It retu 1 min read Scala List splitAt() method with example The splitAt() method belongs to the value member of the class List. It is utilized to split the given list into a prefix/suffix pair at a stated position. Method Definition: def splitAt(n: Int): (List[A], List[A]) Where, n is the position at which we need to split. Return Type: It returns a pair of 1 min read Scala String trim() method with example The trim() method is utilized to omit the leading and trailing spaces in the stated string. Method Definition: String trim() Return Type: It returns the stated string after removing all the white spaces. Example: 1# Scala // Scala program of trim() // method // Creating object object GfG { // Main m 1 min read Like