Scala String trim() method with example Last Updated : 29 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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 method def main(args:Array[String]) { // Applying trim method val result = " Nidhi Singh ".trim() // Displays output println(result) } } Output: Nidhi Singh Example: 2# Scala // Scala program of trim() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Applying trim method val result = " Nidhi Singh GfG ".trim() // Displays output println(result) } } Output: Nidhi Singh GfG Comment More infoAdvertise with us Next Article Scala String trim() method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Scala-Strings Similar Reads 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 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 Set tail() method with example The tail() method is utilized to return a set consisting all the elements except the first element of the set. Method Definition: def tail: Set[A] Return Type: It returns a set consisting of all the elements except the first element of the set. Example #1: Scala // Scala program of tail() // method 1 min read Scala String toCharArray() method with example The toCharArray() method is utilized to convert a stated string to CharArray. Method Definition: char[] toCharArray() Return Type: It returns CharArray. Example: 1# Scala // Scala program of toCharArray() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Appl 1 min read Scala Set take() method with example The take() method is utilized to return a set consisting of first 'n' elements of the set. Method Definition: def take(n: Int): Set[A] Where 'n' is specifies the number of element to select. Return Type: It returns a set consisting of first 'n' elements of the set. Example #1: Scala // Scala program 1 min read Like