{"id":217,"date":"2022-01-21T12:04:15","date_gmt":"2022-01-21T12:04:15","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/scala\/?p=217"},"modified":"2022-01-21T12:04:15","modified_gmt":"2022-01-21T12:04:15","slug":"scala-string-manipulation","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/scala\/scala-string-manipulation\/","title":{"rendered":"Scala &#8211; String Manipulation"},"content":{"rendered":"<p>In this lesson, you will learn about how to manipulate strings in Scala. Strings in Scala just like in Java are immutable, meaning that they cannot be modified once created.<\/p>\n<ol>\n<li><a href=\"#t1\">String Creation and Concatenation<\/a><\/li>\n<li><a href=\"#t2\">Formatting Strings<\/a><\/li>\n<li><a href=\"#t3\">String Interpolation<\/a><\/li>\n<li><a href=\"#t4\">String Methods<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. String Creation and Concatenation<\/strong><\/h4>\n<p>String are created with a simple assignment operation. For example:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">val<\/span> name<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\u02dcKindson The Genius\"<\/span>\r\n<\/pre>\n<p>This creates a string and assigns it to the variable, name.<\/p>\n<p>To get the length of a string, we use the length method of the String class like so:<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">val<\/span> name<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"\u02dcKindson The Genius\"<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">val<\/span> len<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Int<\/span> <span style=\"color: #333333;\">=<\/span> name<span style=\"color: #333333;\">.<\/span>length<span style=\"color: #333333;\">();<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>String Concatenation<\/strong><\/p>\n<p>To concatenate two strings, you can use either the &#8220;+&#8221;\u00a0 or the concat() method of the String class<\/p>\n<p>The following code demonstrates string concatenation using both methods.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/\/ Program to Concatenate strings<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">object<\/span> <span style=\"color: #bb0066; font-weight: bold;\">StringConcatenation<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\r\n  <span style=\"color: #008800; font-weight: bold;\">val<\/span> firstname<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Kindson\"<\/span>\r\n  <span style=\"color: #008800; font-weight: bold;\">val<\/span> lastname<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Munonye\"<\/span>\r\n\r\n  <span style=\"color: #008800; font-weight: bold;\">def<\/span> main<span style=\"color: #333333;\">(<\/span>args<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Array<\/span><span style=\"color: #333333;\">[<\/span><span style=\"color: #333399; font-weight: bold;\">String<\/span><span style=\"color: #333333;\">])<\/span><span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Unit<\/span> <span style=\"color: #333333;\">={<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">val<\/span> firstname<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Kindson \"<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">val<\/span> lastname<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Munonye\"<\/span>\r\n    println<span style=\"color: #333333;\">(<\/span><span style=\"background-color: #fff0f0;\">\"Fullname: \"<\/span> <span style=\"color: #333333;\">+<\/span> firstname<span style=\"color: #333333;\">.<\/span>concat<span style=\"color: #333333;\">(<\/span>lastname<span style=\"color: #333333;\">))<\/span>\r\n  <span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>The program above uses the &#8220;+&#8221; operator as well as the concat() function to join the strings.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Formatting Strings<\/strong><\/h4>\n<p>You can use the format method to format a string in Scala. This works just the same way we used the .concat method.<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #888888;\">\/\/ Program to Demonstrate String Format<\/span>\r\n<span style=\"color: #008800; font-weight: bold;\">object<\/span> <span style=\"color: #bb0066; font-weight: bold;\">StringFormat<\/span> <span style=\"color: #333333;\">{<\/span>\r\n\r\n  <span style=\"color: #008800; font-weight: bold;\">val<\/span> name<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Kindson Munonye\"<\/span>\r\n  <span style=\"color: #008800; font-weight: bold;\">val<\/span> location<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Budapest\"<\/span>\r\n  <span style=\"color: #008800; font-weight: bold;\">val<\/span> age<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Int<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">39<\/span>\r\n\r\n  <span style=\"color: #008800; font-weight: bold;\">def<\/span> main<span style=\"color: #333333;\">(<\/span>args<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Array<\/span><span style=\"color: #333333;\">[<\/span><span style=\"color: #333399; font-weight: bold;\">String<\/span><span style=\"color: #333333;\">])<\/span><span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Unit<\/span> <span style=\"color: #333333;\">={<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">val<\/span> str<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"I am %s I live in %s. I am %d years old\"<\/span><span style=\"color: #333333;\">.<\/span>format<span style=\"color: #333333;\">(<\/span>name<span style=\"color: #333333;\">,<\/span> location<span style=\"color: #333333;\">,<\/span> age<span style=\"color: #333333;\">)<\/span>\r\n    println<span style=\"color: #333333;\">(<\/span>str<span style=\"color: #333333;\">)<\/span>\r\n  <span style=\"color: #333333;\">}<\/span>\r\n<span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>In the code above, each format specification is replaced by the corresponding string in order.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. String Interpolation<\/strong><\/h4>\n<p>This is an interesting way of creating strings in Scala programming language. In string interpolation, you can embed variable reference directly into the string literal without having to use the .format() keyword.<\/p>\n<p><strong>The &#8216;S&#8217;\u00a0<\/strong><b>Interpolator<\/b><\/p>\n<p>When you prepend the the literal &#8216;s&#8217;\u00a0 to a string, then any string variable within the scope of the function can be embedded into the string. An example is given below<\/p>\n<pre style=\"margin: 0; line-height: 125%;\">  <span style=\"color: #008800; font-weight: bold;\">def<\/span> main<span style=\"color: #333333;\">(<\/span>args<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Array<\/span><span style=\"color: #333333;\">[<\/span><span style=\"color: #333399; font-weight: bold;\">String<\/span><span style=\"color: #333333;\">])<\/span><span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Unit<\/span> <span style=\"color: #333333;\">={<\/span>\r\n\r\n    <span style=\"color: #008800; font-weight: bold;\">val<\/span> name<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Kindson Munonye\"<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">val<\/span> location<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Budapest\"<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">val<\/span> age<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Int<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #0000dd; font-weight: bold;\">39<\/span>\r\n\r\n    println<span style=\"color: #333333;\">(<\/span>s<span style=\"background-color: #fff0f0;\">\"My name is $name . I live in $location. I am $age years old\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n  <span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>You can also use expressions as for string interpolation. You simply enclose the expression in curly braces. At run time the expression is evaluated and the result is displayed. For example<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<pre style=\"margin: 0; line-height: 125%;\">println<span style=\"color: #333333;\">(<\/span>s <span style=\"color: #ff0000; background-color: #ffaaaa;\">\u201c<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">2<\/span> <span style=\"color: #008800; font-weight: bold;\">=<\/span> $<span style=\"color: #333333;\">{<\/span><span style=\"color: #0000dd; font-weight: bold;\">2<\/span> <span style=\"color: #333333;\">+<\/span> <span style=\"color: #0000dd; font-weight: bold;\">2<\/span><span style=\"color: #333333;\">}<\/span><span style=\"color: #ff0000; background-color: #ffaaaa;\">\u201d<\/span><span style=\"color: #333333;\">)<\/span> <span style=\"color: #888888;\">\/\/output: 2 + 2 = 4<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>The &#8216;f&#8217; Interpolator<\/strong><\/p>\n<p>The &#8216;f&#8217; interpolator allows you to create formatted string similar to C language. With the &#8216;f&#8217; interpolator,\u00a0 the variable references\u00a0 should be followed by format specifiers such as %d, %s , %i and %f.<\/p>\n<p>The program below prints out a string using the &#8216;f&#8217; interpolator<\/p>\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #008800; font-weight: bold;\">def<\/span> main<span style=\"color: #333333;\">(<\/span>args<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Array<\/span><span style=\"color: #333333;\">[<\/span><span style=\"color: #333399; font-weight: bold;\">String<\/span><span style=\"color: #333333;\">])<\/span><span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Unit<\/span> <span style=\"color: #333333;\">={<\/span>\r\n  \r\n    <span style=\"color: #008800; font-weight: bold;\">val<\/span> score<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">Double<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"color: #6600ee; font-weight: bold;\">98.89<\/span>\r\n    <span style=\"color: #008800; font-weight: bold;\">val<\/span> name<span style=\"color: #008800; font-weight: bold;\">:<\/span> <span style=\"color: #333399; font-weight: bold;\">String<\/span> <span style=\"color: #333333;\">=<\/span> <span style=\"background-color: #fff0f0;\">\"Munonye\"<\/span>\r\n    println<span style=\"color: #333333;\">(<\/span>f<span style=\"background-color: #fff0f0;\">\"$name%s scored $score%2.2f\"<\/span><span style=\"color: #333333;\">)<\/span>\r\n  <span style=\"color: #333333;\">}<\/span>\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>The &#8216;raw&#8217; Interpolator<\/strong><\/p>\n<p>This is similar to the &#8216;s&#8217; interpolator but performs no escaping of the literals within the string. I recommend you try it out yourself.<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. String Methods<\/strong><\/h4>\n<p>The table below shows a list of string methods in Scala. These methods are defined in the java.lang.String class.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SN<\/th>\n<th>Methods and Description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><b>char charAt(int index) &#8211;\u00a0<\/b>Returns the character at the given index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><b>int compareTo(Object o) &#8211;\u00a0<\/b>Compares this String to another Object.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><b>int compareTo(String anotherString) &#8211;\u00a0<\/b>Compares two strings lexicographically.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><b>int compareToIgnoreCase(String str) &#8211;\u00a0<\/b>Compares two strings lexicographically, ignoring case differences.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><b>String concat(String str) &#8211;\u00a0<\/b>Concatenates the specified string to the end of this string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><b>boolean contentEquals(StringBuffer sb) &#8211;\u00a0<\/b>Returns true if and only if this String represents the same sequence of characters as the given StringBuffer.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><b>static String copyValueOf(char[] data) &#8211;\u00a0<\/b>Returns a String that represents the character sequence in the given array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">8<\/td>\n<td><b>static String copyValueOf(char[] data, int offset, int count) &#8211;\u00a0<\/b>Returns a String that represents the character sequence in the given array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">9<\/td>\n<td><b>boolean endsWith(String suffix) &#8211;\u00a0<\/b>Tests if this string ends with the given suffix.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">10<\/td>\n<td><b>boolean equals(Object anObject) &#8211;\u00a0<\/b>Compares this string to the given object.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">11<\/td>\n<td><b>boolean equalsIgnoreCase(String anotherString) &#8211;\u00a0<\/b>Compares this String to another String, ignoring case considerations.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">12<\/td>\n<td><b>byte getBytes() &#8211;\u00a0<\/b>Encodes this String into a sequence of bytes using the platform&#8217;s default charset, storing the result into a new byte array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">13<\/td>\n<td><b>byte[] getBytes(String charsetName) &#8211;\u00a0<\/b>Encodes this String into a sequence of bytes using the named charset, storing the result into a new byte array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">14<\/td>\n<td><b>void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) &#8211;\u00a0<\/b>Copies characters from this string into the destination character array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">15<\/td>\n<td><b>int hashCode() &#8211;\u00a0<\/b>Returns a hash code for this string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">16<\/td>\n<td><b>int indexOf(int ch) &#8211;\u00a0<\/b>Returns the index within this string of the first occurrence of the given character.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">17<\/td>\n<td><b>int indexOf(int ch, int fromIndex) &#8211;\u00a0<\/b>Returns the index within this string of the first occurrence of the specified character, starting the search at the given index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">18<\/td>\n<td><b>int indexOf(String str) &#8211;\u00a0<\/b>Returns the index within this string of the first occurrence of the given substring.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">19<\/td>\n<td><b>int indexOf(String str, int fromIndex) &#8211;\u00a0<\/b>Returns the index within this string of the first occurrence of the specified substring, starting at the given index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">20<\/td>\n<td><b>String intern() &#8211;\u00a0<\/b>Returns a canonical representation for the string object.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">21<\/td>\n<td><b>int lastIndexOf(int ch) &#8211;\u00a0<\/b>Returns the index within this string of the last occurrence of the given character.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">22<\/td>\n<td><b>int lastIndexOf(int ch, int fromIndex) &#8211;\u00a0<\/b>Returns the index within this string of the last occurrence of the specified character, searching backward starting at the given index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">23<\/td>\n<td><b>int lastIndexOf(String str) &#8211;\u00a0<\/b>Returns the index within this string of the rightmost occurrence of the given substring.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">24<\/td>\n<td><b>int lastIndexOf(String str, int fromIndex) &#8211;\u00a0<\/b>Returns the index within this string of the last occurrence of the specified substring, searching backward starting at the given index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">25<\/td>\n<td><b>int length() &#8211;\u00a0<\/b>Returns the length of the string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">26<\/td>\n<td><b>boolean matches(String regex) &#8211;\u00a0<\/b>Tells if or not this string matches the given regular expression.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">27<\/td>\n<td><b>boolean regionMatches(boolean ignoreCase, int toffset, String other, int offset, int len) &#8211;\u00a0<\/b>Checks if two string regions are equal.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">28<\/td>\n<td><b>boolean regionMatches(int toffset, String other, int offset, int len) &#8211;\u00a0<\/b>Checks if two string regions are equal.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">29<\/td>\n<td><b>String replace(char\u00a0<i>oldChar<\/i>, char newChar) &#8211;\u00a0<\/b>Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">30<\/td>\n<td><b>String replaceAll(String regex, String replacement &#8211;\u00a0<\/b>Replaces each substring of this string that matches the given regular expression with the given replacement.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">31<\/td>\n<td><b>String replaceFirst(String regex, String replacement) &#8211;\u00a0<\/b>Replaces the first substring of this string that matches the given regular expression with the given replacement.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">32<\/td>\n<td><b>String[] split(String regex) &#8211;\u00a0<\/b>Splits this string around matches of the given regular expression.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">33<\/td>\n<td><b>String[] split(String regex, int limit) &#8211;\u00a0<\/b>Splits this string around matches of the given regular expression.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">34<\/td>\n<td><b>boolean startsWith(String prefix) &#8211;\u00a0<\/b>Tests if this string starts with the given prefix.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">35<\/td>\n<td><b>boolean startsWith(String prefix, int toffset) &#8211;\u00a0<\/b>Tests if this string starts with the specified prefix beginning a given index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">36<\/td>\n<td><b>CharSequence subSequence(int beginIndex, int endIndex) &#8211;\u00a0<\/b>Returns a new character sequence that is a subsequence of this sequence.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">37<\/td>\n<td><b>String substring(int beginIndex) &#8211;\u00a0<\/b>Returns a new string that is a substring of this string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">38<\/td>\n<td><b>String substring(int beginIndex, int endIndex) &#8211;\u00a0<\/b>Returns a new string that is a substring of this string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">39<\/td>\n<td><b>char[] toCharArray() &#8211;\u00a0<\/b>Converts a string to a new character array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">40<\/td>\n<td><b>String toLowerCase() &#8211;\u00a0<\/b>Converts all of the characters in the String to lower case using the rules of the default locale.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">41<\/td>\n<td><b>String toLowerCase(Locale locale) &#8211;\u00a0<\/b>Converts all of the characters in this String to lower case using the rules of the given Locale.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">42<\/td>\n<td><b>String toString() &#8211;\u00a0<\/b>This object (which is already a string!) is itself returned.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">43<\/td>\n<td><b>String toUpperCase() &#8211;\u00a0<\/b>Converts all of the characters in this String to upper case using the rules of the default locale.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">44<\/td>\n<td><b>String toUpperCase(Locale locale) &#8211;\u00a0<\/b>Converts all of the characters in this String to upper case using the rules of the given Locale.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">45<\/td>\n<td><b>String trim() &#8211;\u00a0<\/b>Returns a copy of the string, with leading and trailing whitespace omitted.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">46<\/td>\n<td><b>static String valueOf(primitive data type x) &#8211;\u00a0<\/b>Returns the string representation of the passed data type argument.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>In this lesson, you will learn about how to manipulate strings in Scala. Strings in Scala just like in Java are immutable, meaning that they &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[35],"class_list":["post-217","post","type-post","status-publish","format-standard","hentry","category-scala-programming","tag-strings-in-scala"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/comments?post=217"}],"version-history":[{"count":2,"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/posts\/217\/revisions"}],"predecessor-version":[{"id":219,"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/posts\/217\/revisions\/219"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/media?parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/categories?post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/scala\/wp-json\/wp\/v2\/tags?post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}