Scala String replaceAll() method with example Last Updated : 03 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The replaceAll() method is used to replace each of the stated sub-string of the string which matches the regular expression with the string we supply in the argument list. Method Definition: String replaceAll(String regex, String replacement) Return Type: It returns the stated string after replacing the stated sub-string with the string we provide. Example #1: Scala // Scala program of replaceAll() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying replaceAll method val result = "csoNidhimso".replaceAll(".so", "##") // Displays output println(result) } } Output: ##Nidhi## Example #2: Scala // Scala program of replaceAll() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying replaceAll method val result = "csoNidhimsoSingh ".replaceAll(".so", "##") // Displays output println(result) } } Output: ##Nidhi##Singh Comment More infoAdvertise with us Next Article Scala String replaceAll() method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Scala-Strings Similar Reads Scala String replace() method with example The replace() method is used to replace the old character of the string with the new one which is stated in the argument. Method Definition: String replace(char oldChar, char newChar) Return Type: It returns the stated string after replacing the old character with the new one. Example #1: Scala // S 1 min read Scala String replaceFirst() method with example The replaceFirst() method is same as replaceAll but here only the first appearance of the stated sub-string will be replaced. Method Definition: String replaceFirst(String regex, String replacement) Return Type: It returns the stated string after replacing the first appearance of stated regular expr 1 min read Scala - String Methods with Examples In Scala, as in Java, a string is a sequence of characters. In Scala, objects of String are immutable which means a constant and cannot be changed once created. In the rest of this section, we discuss the important methods of java.lang.String class. char charAt(int index): This method is used to ret 12 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 Scala Set toString() method with example The toString() method is utilized to return a string consisting of all the elements of the set. Method Definition: def toString(): String Return Type: It returns a string consisting of all the elements of the set. Example #1: Scala // Scala program of toString() // method // Creating object object G 1 min read Like