

{"id":13224,"date":"2018-04-12T05:55:46","date_gmt":"2018-04-12T05:55:46","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=13224"},"modified":"2021-12-04T10:16:30","modified_gmt":"2021-12-04T04:46:30","slug":"scala-string-method","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/scala-string-method\/","title":{"rendered":"Scala String Method with Syntax and Method"},"content":{"rendered":"<h3>Scala String Method &#8211; Object<\/h3>\n<p>In this tutorial on Scala String Method, we will discuss the methods defined by the class java.lang.String. Before you proceed with this, you should check out a brief introduction to Strings in Scala.<\/p>\n<p>So, let&#8217;s start Scala String Method Tutorial.<\/p>\n<h3>List of String Method in Scala with Example<\/h3>\n<h4>1. char charAt(int index)<\/h4>\n<p>This method returns the character at the index we pass to it. Isn\u2019t it so much like Java?<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".charAt(1)\r\nres2: Char = y<\/pre>\n<h4>2. int compareTo(Object o)<\/h4>\n<p>This Scala String Method compares a string to another object.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".compareTo(\"Ayush\")\r\nres10: Int = 1<\/pre>\n<h4>3. int compareTo(String anotherString)<\/h4>\n<p>This is like the previous one, except that it compares two strings lexicographically. If they match, it returns 0. Otherwise, it returns the difference between the two(the number of characters less in the shorter string, or the maximum ASCII difference between the two).<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".compareTo(\"Ayushi \")\r\nres3: Int = -1\r\nscala&gt; \"Ayushi\".compareTo(\"Ayushi\")\r\nres4: Int = 0\r\nscala&gt; \"Ayushi\".compareTo(\"ayushi\")\r\nres5: Int = -32<\/pre>\n<p>Comparing to a different type raises a type-mismatch error.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".compareTo(7)\r\n&lt;console&gt;:12: error: type mismatch;\r\nfound   : Int(7)\r\nrequired: String\r\n      \"Ayushi\".compareTo(7)\r\n                         ^<\/pre>\n<h4>4. int compareToIgnoreCase(String str)<\/h4>\n<p>int compareToIgnoreCase Scala String Method compares two strings lexicographically, while ignoring the case differences.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".compareToIgnoreCase(\"ayushi\")\r\nres21: Int = 0\r\nscala&gt; \"Ayushi\".compareToIgnoreCase(\"ayushi \")\r\nres22: Int = -1\r\nscala&gt; \"Ayushi\".compareToIgnoreCase(\"aYushi\")\r\nres41: Int = 0<\/pre>\n<h4>5. String concat(String str)<\/h4>\n<p>This will concatenate the string in the parameter to the end of the string on which we call it. We saw this when we talked about strings briefly.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".concat(\"Sharma\")\r\nres23: String = AyushiSharma<\/pre>\n<h4>6. Boolean contentEquals(StringBuffer sb)<\/h4>\n<p>contentEquals compares a string to a StringBuffer\u2019s contents. If equal, it returns true; otherwise, false.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; val a=new StringBuffer(\"Ayushi\")\r\na: StringBuffer = Ayushi\r\nscala&gt; \"Ayushi\".contentEquals(a)\r\nres24: Boolean = true\r\nscala&gt; \"ayushi\".contentEquals(a)\r\nres25: Boolean = false<\/pre>\n<h4>7. Boolean endsWith(String suffix)<\/h4>\n<p>This Scala String Method returns true if the string ends with the suffix specified; otherwise, false.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".endsWith(\"i\")\r\nres32: Boolean = true\r\nscala&gt; \"Ayushi\".endsWith(\"sha\")\r\nres33: Boolean = false<\/pre>\n<h4>8. Boolean equals(Object anObject)<\/h4>\n<p>This Scala String Method returns true if the string and the object are equal; otherwise, false.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; val b=Array('A','y','u','s','h','i')\r\nb: Array[Char] = Array(A, y, u, s, h, i)\r\nscala&gt; \"Ayushi\".equals(b)\r\nres34: Boolean = false\r\nscala&gt; \"Ayushi\".equals(\"ayushi\")\r\nres35: Boolean = false\r\nscala&gt; \"Ayushi\".equals(\"Ayushi\")\r\nres36: Boolean = true\r\nscala&gt; val b=Array(\"Ayushi\")\r\nb: Array[String] = Array(Ayushi)\r\nscala&gt; \"Ayushi\".equals(b)\r\nres37: Boolean = false\r\nscala&gt; \"Ayushi\".equals(7)\r\nres39: Boolean = false\r\nscala&gt; \"7\".equals(7)\r\nres40: Boolean = false\r\nscala&gt; \"Ayushi\".equals(\"aYushi\")\r\nres43: Boolean = false<\/pre>\n<h4>9. Boolean equalsIgnoreCase(String anotherString)<\/h4>\n<p>This is like equals(), except that it ignores case differences.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".equalsIgnoreCase(\"aYushi\")\r\nres42: Boolean = true<\/pre>\n<h4>10. byte getBytes()<\/h4>\n<p>getBytes Scala String Method encodes a string into a sequence of bytes and stores it into a new byte array. It uses the platform\u2019s default charset for this.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".getBytes()\r\nres44: Array[Byte] = Array(65, 121, 117, 115, 104, 105)\r\nscala&gt; \"ABCcba\".getBytes()\r\nres45: Array[Byte] = Array(65, 66, 67, 99, 98, 97)\r\nscala&gt; \" \".getBytes()\r\nres46: Array[Byte] = Array(32)<\/pre>\n<h4>11. byte[] getBytes(String charsetName)<\/h4>\n<p>With a named charset as a parameter, getBytes will use that charset to encode the string.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".getBytes(\"Unicode\")\r\nres47: Array[Byte] = Array(-2, -1, 0, 65, 0, 121, 0, 117, 0, 115, 0, 104, 0, 105)\r\nscala&gt; \"Ayushi\".getBytes(\"UTF-8\")\r\nres48: Array[Byte] = Array(65, 121, 117, 115, 104, 105)<\/pre>\n<p>However, providing an invalid charset name will result in an error:<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".getBytes(\"Union\")\r\njava.io.UnsupportedEncodingException: Union\r\n at java.lang.StringCoding.encode(Unknown Source)\r\n at java.lang.String.getBytes(Unknown Source)\r\n ... 28 elided<\/pre>\n<h4>12. void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)<\/h4>\n<p>This Scala String Method copies characters from the string into the destination character array. scrBegin denotes the index to begin at in the source string, and srcEnd denotes the index to end at in the source string. dstBegin denotes the index to begin at in the destination character array. dst is the destination character array.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; var c:Array[Char]=Array('A','y','u','s','h','i')\r\nc: Array[Char] = Array(A, y, u, s, h, i)\r\nscala&gt; var d=\"01234\"\r\nd: String = 01234\r\nscala&gt; d.getChars(2,4,c,2)\r\nscala&gt; c\r\nres57: Array[Char] = Array(A, y, 2, 3, h, i)<\/pre>\n<h4>13. int hashCode()<\/h4>\n<p>This int hashCode method returns a hash code for the string.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".hashCode()\r\nres58: Int = 1976240247\r\nscala&gt; val name=\"Ayushi\"\r\nname: String = Ayushi\r\nscala&gt; name.hashCode()\r\nres60: Int = 1976240247<\/pre>\n<h4>14. int indexOf(int ch)<\/h4>\n<p>This Scala Sring returns the index of the first occurrence of the character ch in the string.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Banana\".indexOf('a')\r\nres61: Int = 1\r\nscala&gt; \"Banana\".indexOf('n')\r\nres62: Int = 2<\/pre>\n<h4>15. int indexOf(int ch, int fromIndex)<\/h4>\n<p>This is like indexOf, except that it begins searching at the index we specify.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Banana\".indexOf('a',2)\r\nres63: Int = 3<\/pre>\n<h4>16. int indexOf(String str)<\/h4>\n<p>This Scala String Method returns the index of the first occurrence of the substring we specify, in the string.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Banana\".indexOf(\"na\")\r\nres64: Int = 2<\/pre>\n<h4>17. int indexOf(String str, int fromIndex)<\/h4>\n<p>Like the other version of indexOf for a single character, this begins searching at the index we specify.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Banana\".indexOf(\"na\",3)\r\nres66: Int = 4<\/pre>\n<h4>18. String intern()<\/h4>\n<p>intern returns the canonical representation for the string object.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Hello,\\n\\tWorld\".intern()\r\nres69: String =\r\nHello,\r\n       World<\/pre>\n<h4>19. int lastIndexOf(int ch)<\/h4>\n<p>Unlike indexOf, this Scala String Method returns the index of the last occurrence of the character we specify.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Banana\".lastIndexOf('n')\r\nres70: Int = 4<\/pre>\n<h4>20. int lastIndexOf(int ch, int fromIndex)<\/h4>\n<p>This is like lastIndexOf, except that it begins searching backwards(right to left), starting at the index we specify.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Banana\".lastIndexOf('n',1)\r\nres71: Int = -1\r\nHere, it returns -1 because it couldn\u2019t find \u2018n\u2019.\r\nscala&gt; \"Banana\".lastIndexOf('n',3)\r\nres72: Int = 2<\/pre>\n<h4>21. int lastIndexOf(String str)<\/h4>\n<p>This Scala String Method returns the index of the last occurrence of the substring we specify, in the string.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Banana\".lastIndexOf(\"na\")\r\nres73: Int = 4<\/pre>\n<h4>22. int lastIndexOf(String str, int fromIndex)<\/h4>\n<p>This Scala String Method is like the previous method, except that it begins searches at the index we specify, and searches right to left.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Banana\".lastIndexOf(\"na\",3)\r\nres74: Int = 2\r\nscala&gt; \"Banana\".lastIndexOf(\"na\",2)\r\nres75: Int = 2\r\nscala&gt; \"Banana\".lastIndexOf(\"na\",1)\r\nres76: Int = -1<\/pre>\n<h4>23. int length()<\/h4>\n<p>This Scala String Method method simply returns the length of a string.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi!\".length()\r\nres77: Int = 7\r\nscala&gt; \"\".length()\r\nres78: Int = 0<\/pre>\n<h4>24. Boolean matches(String regex)<\/h4>\n<p>If the string matches the regular expression we specify, this returns true; otherwise, false.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".matches(\".i.*\")\r\nres80: Boolean = false\r\nscala&gt; \"Ayushi\".matches(\".*i\")\r\nres79: Boolean = true<\/pre>\n<h4>25. Boolean regionMatches(boolean ignoreCase, int toffset, String other, int offset, int len)<\/h4>\n<p>If two string regions are equal, this returns true; otherwise, false. ignoreCase, when set to true, will ignore the case differences.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".regionMatches(true,0,\"Ayushi\",0,4)\r\nres81: Boolean = true\r\nscala&gt; \"Ayushi\".regionMatches(true,0,\"Ayush\",0,4)\r\nres82: Boolean = true\r\nscala&gt; \"Ayushi\".regionMatches(true,0,\"Ayush\",0,3)\r\nres83: Boolean = true\r\nscala&gt; \"Ayushi\".regionMatches(true,0,\"Ay\",0,3)\r\nres84: Boolean = false<\/pre>\n<h4>26. Boolean regionMatches(int toffset, String other, int offset, int len)<\/h4>\n<p>This is like the previous method, except that it doesn\u2019t have ignoreCase.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".regionMatches(0,\"Ayu\",0,2)\r\nres85: Boolean = true\r\nscala&gt; \"Ayushi\".regionMatches(0,\"Ayu\",0,4)\r\nres86: Boolean = false<\/pre>\n<h4>27. String replace(char oldChar, char newChar)<\/h4>\n<p>Replace will replace all occurrences of oldChar in the string with newChar, and return the resultant string.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi sharma\".replace('s','$')\r\nres87: String = Ayu$hi $harma\r\nscala&gt; \"Ayushi Sharma\".replace('s','$')\r\nres88: String = Ayu$hi Sharma<\/pre>\n<h4>28. String replaceAll(String regex, String replacement)<\/h4>\n<p>This will replace each substring matching the regular expression. It will replace it with the replacement string we provide.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"potdotnothotokayslot\".replaceAll(\".ot\",\"**\")\r\nres89: String = ********okays**<\/pre>\n<h4>29. String replaceFirst(String regex, String replacement)<\/h4>\n<p>If in the above example, we want to replace only the first such occurrence:<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"potdotnothotokayslot\".replaceFirst(\".ot\",\"**\")\r\nres90: String = **dotnothotokayslot<\/pre>\n<h4>30. String[] split(String regex)<\/h4>\n<p>This Scala String Method splits the string around matches of the regular expression we specify. It returns a String array.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"xpotxdotynotzhotokayslot\".split(\".ot\")\r\nres93: Array[String] = Array(x, x, y, z, okays)<\/pre>\n<h4>31. String[] split(String regex, int limit)<\/h4>\n<p>This Scala String Method is like split, except that we can limit the number of members for the array. The last member, then, is whatever part of the string that\u2019s left.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"xpotxdotynotzhotokayslot\".split(\".ot\",2)\r\nres94: Array[String] = Array(x, xdotynotzhotokayslot)\r\nscala&gt; \"xpotxdotynotzhotokayslot\".split(\".ot\",5)\r\nres95: Array[String] = Array(x, x, y, z, okayslot)<\/pre>\n<h4>32. Boolean startsWith(String prefix)<\/h4>\n<p>If the string starts with the prefix we specify, this returns true; otherwise, false. This is like endsWith.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".startsWith(\"Ay\")\r\nres97: Boolean = true\r\nscala&gt; \"Ayushi\".startsWith(\" A\")\r\nres99: Boolean = false\r\nscala&gt; \"Ayushi\".startsWith(\"ayu\")\r\nres100: Boolean = false<\/pre>\n<h4>33. Boolean startsWith(String prefix, int toffset)<\/h4>\n<p>If the string starts with the specified prefix at the index we specify, This Scala string method returns true; otherwise, false.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".startsWith(\"yu\",1)\r\nres101: Boolean = true<\/pre>\n<h4>34. CharSequence subSequence(int beginIndex, int endIndex)<\/h4>\n<p>This returns a subsequence from the string, beginning at <i>beginIndex<\/i> and ending at <i>endIndex<\/i>.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".subSequence(1,4)\r\nres102: CharSequence = yus<\/pre>\n<h4>35. String substring(int beginIndex)<\/h4>\n<p>This Scala String Method returns the contents of the string beginning at <i>beginIndex<\/i>.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".substring(3)\r\nres103: String = shi<\/pre>\n<h4>36. String substring(int beginIndex, int endIndex)<\/h4>\n<p>This returns the part of the string beginning at <i>beginIndex<\/i> and ending at <i>endIndex<\/i>. Wait, isn\u2019t that the same as subsequence? Check the types of the results:<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; var a=\"Ayushi\".subSequence(1,4)\r\na: CharSequence = yus\r\nscala&gt; var b=\"Ayushi\".substring(1,4)\r\nb: String = yus<\/pre>\n<p>While one returns a CharSequence, the other returns a String.<\/p>\n<h4>37. char[] toCharArray()<\/h4>\n<p>This converts the string into a CharArray, and then returns it.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".toCharArray()\r\nres104: Array[Char] = Array(A, y, u, s, h, i)<\/pre>\n<h4>38. String toLowerCase()<\/h4>\n<p>This String Method in Scala converts all characters in the string to lower case, and then returns the resultant string.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"AyU$#I!\".toLowerCase()\r\nres105: String = ayu$#i!<\/pre>\n<h4>39. String toLowerCase(Locale locale)<\/h4>\n<p>This is like toLowerCase, except that we can specify the locale to follow the rules of.<\/p>\n<h4>40. String toString()<\/h4>\n<p>This returns a String object itself.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"7\".toString()\r\nres108: String = 7<\/pre>\n<h4>41. String toUpperCase()<\/h4>\n<p>This Scala String Method is like toLowerCase, and converts all characters in the string to upper case.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"Ayushi\".toUpperCase()\r\nres109: String = AYUSHI<\/pre>\n<h4>42. String toUpperCase(Locale locale)<\/h4>\n<p>This is like the previous method, except that it will follow the rules of the given locale.<\/p>\n<h4>43. String trim()<\/h4>\n<p>Trim will elide the leading and trailing whitespaces from the string, and then return it.<\/p>\n<pre class=\"EnlighterJSRAW\">scala&gt; \"         Ayushi \".trim()\r\nres110: String = Ayushi<\/pre>\n<p>So, this was all about Scala String Methods. Hope you like our explanation.<\/p>\n<h3>3.Conclusion<\/h3>\n<p>These are the 43 methods we can directly call on a String in Scala. Hope we\u2019ve done our job in explaining them efficiently and clearly. Still, had a confusion, feel free to share with us!<\/p>\n<p><a href=\"http:\/\/otfried.org\/scala\/string.html\"><strong>Reference<\/strong><\/a><span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:1988,&quot;href&quot;:&quot;http:\\\/\\\/otfried.org\\\/scala\\\/string.html&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250119131332\\\/https:\\\/\\\/otfried.org\\\/scala\\\/string.html&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-10 15:30:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-07 07:45:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 23:10:58&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-22 01:09:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 09:30:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-21 16:29:02&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-03-04 22:09:39&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-15 12:37:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-17 05:55:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-26 00:03:47&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-30 16:42:21&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-07-07 01:16:54&quot;,&quot;http_code&quot;:503}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-07-07 01:16:54&quot;,&quot;http_code&quot;:503},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Scala String Method &#8211; Object In this tutorial on Scala String Method, we will discuss the methods defined by the class java.lang.String. Before you proceed with this, you should check out a brief introduction&#46;&#46;&#46;<\/p>\n","protected":false},"author":6,"featured_media":31090,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[61],"tags":[7144,12555],"class_list":["post-13224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scala","tag-introduction-to-strings-in-scala","tag-scala-string-method"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Scala String Method with Syntax and Method - DataFlair<\/title>\n<meta name=\"description\" content=\"Scala String Method: Learn methods defined by the class java.lang.String. Also check out a brief introduction to Strings in Scala.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/scala-string-method\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala String Method with Syntax and Method - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Scala String Method: Learn methods defined by the class java.lang.String. Also check out a brief introduction to Strings in Scala.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/scala-string-method\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-04-12T05:55:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-04T04:46:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/String-Methods-in-Scala-01-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala String Method with Syntax and Method - DataFlair","description":"Scala String Method: Learn methods defined by the class java.lang.String. Also check out a brief introduction to Strings in Scala.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/scala-string-method\/","og_locale":"en_US","og_type":"article","og_title":"Scala String Method with Syntax and Method - DataFlair","og_description":"Scala String Method: Learn methods defined by the class java.lang.String. Also check out a brief introduction to Strings in Scala.","og_url":"https:\/\/data-flair.training\/blogs\/scala-string-method\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-04-12T05:55:46+00:00","article_modified_time":"2021-12-04T04:46:30+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/String-Methods-in-Scala-01-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89"},"headline":"Scala String Method with Syntax and Method","datePublished":"2018-04-12T05:55:46+00:00","dateModified":"2021-12-04T04:46:30+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/"},"wordCount":1137,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/String-Methods-in-Scala-01-1.jpg","keywords":["introduction to Strings in Scala","Scala String Method"],"articleSection":["Scala Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/scala-string-method\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/","url":"https:\/\/data-flair.training\/blogs\/scala-string-method\/","name":"Scala String Method with Syntax and Method - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/String-Methods-in-Scala-01-1.jpg","datePublished":"2018-04-12T05:55:46+00:00","dateModified":"2021-12-04T04:46:30+00:00","description":"Scala String Method: Learn methods defined by the class java.lang.String. Also check out a brief introduction to Strings in Scala.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/scala-string-method\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/String-Methods-in-Scala-01-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/04\/String-Methods-in-Scala-01-1.jpg","width":1200,"height":628,"caption":"String In Scala"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/scala-string-method\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Scala Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/scala\/"},{"@type":"ListItem","position":3,"name":"Scala String Method with Syntax and Method"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/2c58ecb4f73a39f0ef993f1ddfcd7b89","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1ce4a0e3e542444fc73bbebf83e89e8b73e2d95ccb1fcee64da9945f078b97c5?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"The DataFlair Team provides industry-driven content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our expert educators focus on delivering value-packed, easy-to-follow resources for tech enthusiasts and professionals.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam2\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/13224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=13224"}],"version-history":[{"count":7,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/13224\/revisions"}],"predecessor-version":[{"id":104794,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/13224\/revisions\/104794"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/31090"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=13224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=13224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=13224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}