{"id":111,"date":"2019-01-20T20:56:37","date_gmt":"2019-01-20T20:56:37","guid":{"rendered":"https:\/\/www.kindsonthegenius.com\/java\/?p=111"},"modified":"2019-03-02T04:38:23","modified_gmt":"2019-03-02T04:38:23","slug":"23-java-string-methods","status":"publish","type":"post","link":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/","title":{"rendered":"Java &#8211; String Methods"},"content":{"rendered":"<p>In this lesson, we are going to learn about various String methods. If you would need to manipulate strings, then these methods are handy.<\/p>\n<p>&nbsp;<\/p>\n<p>Now, we are going to learn about six categories of methods<\/p>\n<ol>\n<li><a href=\"#t1\">Indexing Methods<\/a><\/li>\n<li><a href=\"#t2\">Comparison Methods<\/a><\/li>\n<li><a href=\"#t3\">Modifier Methods<\/a><\/li>\n<li><a href=\"#t4\">Case Modifiers Methods<\/a><\/li>\n<li><a href=\"#t5\">Substring Methods<\/a><\/li>\n<li><a href=\"#t6\">Byte and Character Methods<\/a><\/li>\n<li><a href=\"#t7\">Matching Methods<\/a><\/li>\n<li><a href=\"#t8\">Misc Methods<\/a><\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t1\">1. Indexing Methods<\/strong><\/h4>\n<p>You you the indexing methods to find positions inside the string.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><strong>int indexOf(int ch)<\/strong><\/p>\n<p>Returns the index within this string of the first occurrence of the given character.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>int indexOf(int ch, int fromIndex)<\/strong><\/p>\n<p>Returns the index within this string of the first occurrence of the given character, starting the search at the specified index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><strong>int indexOf(String str)<\/strong><\/p>\n<p>Returns the index within this string of the first occurrence of the given substring.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><strong>int indexOf(String str, int fromIndex)<\/strong><\/p>\n<p>Returns the index within this string of the first occurrence of the given\u00a0 substring, starting at the specified index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><strong>int lastIndexOf(int ch)<\/strong><\/p>\n<p>Returns the index within this string of the last occurrence of the given\u00a0 character.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><strong>int lastIndexOf(int ch, int fromIndex)<\/strong><\/p>\n<p>Returns the index within this string of the last occurrence of the given character, searching backward starting at the specified index.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><strong>int lastIndexOf(String str)<\/strong><\/p>\n<p>Returns the index within this string of the rightmost occurrence of the given substring.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">8.<\/td>\n<td><strong>int lastIndexOf(String str, int fromIndex)<\/strong><\/p>\n<p>Returns the index within this string of the last occurrence of the given substring, searching backward starting at the specified index.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t2\">2. Comparison Methods<\/strong><\/h4>\n<p>We use the comparison to compare a string to another string or object.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>SN<\/th>\n<th>Method and brief description<\/th>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>int compareTo(Object o)<\/strong><\/p>\n<p>Compares this String to the object given as parameter<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><strong>int compareTo(String anotherString)<\/strong><\/p>\n<p>Compares one string with another string lexicographically.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><strong>int compareToIgnoreCase(String str)<\/strong><\/p>\n<p>Compares one string with another string lexicographically, and ignores case differences.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><strong>boolean equals(Object anObject)<\/strong><\/p>\n<p>Compares a string to the specified object and returns true if they are equal. Otherwise returns false.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><strong>boolean equalsIgnoreCase(String anotherString)<\/strong><\/p>\n<p>Compares a String with\u00a0 another String, ignoring case considerations. Returns true if the two strings are equal.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><strong>boolean contentEquals(StringBuffer sb)<\/strong><\/p>\n<p>Returns true if and only if this String represents the same sequence of characters as the given StringBuffer. Returns false if otherwise<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">8<\/td>\n<td><strong>boolean startsWith(String prefix)<\/strong><\/p>\n<p>Checks if this string starts with the given prefix. Returns true if yes, otherwise false.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">9<\/td>\n<td><strong>boolean startsWith(String prefix, int toffset)<\/strong><\/p>\n<p>Checks if a string starts with the given prefix beginning a specified index. It returns true is it does. Else, it returns false.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">10<\/td>\n<td><strong>boolean endsWith(String suffix)<\/strong><\/p>\n<p>Checks if this string ends with the given suffix.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t3\">3. Modifier Methods<\/strong><\/h4>\n<p>You use these set of methods to modify the value of a string. However, keep in mind that the changes are not persisted. This is because, as you know, Strings are immutable.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td class=\"ts\">1.<\/td>\n<td><strong>String replace(char c1, char c2)<\/strong><\/p>\n<p>It returns a new string that results from replacing all occurrences of c1 in this string with c2<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>String replaceAll(String regex, String replacement)<\/strong><\/p>\n<p>It replaces each substring of the string that matches the specified regular expression with the given replacement.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><strong>String replaceFirst(String regex, String replacement)<\/strong><\/p>\n<p>It replaces the first substring of this string that matches the specified regular expression with the given replacement.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><strong>String[] split(String regex)<\/strong><\/p>\n<p>Splits the string around matches of the specified regular expression. returns a string array<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5.<\/td>\n<td><strong>String[] split(String regex, int limit)<\/strong><\/p>\n<p>Splits a string around matches of the specified regular expression. Returns a string array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">6<\/td>\n<td><strong>String trim()<\/strong><\/p>\n<p>It returns a copy of the string, with leading and trailing whitespace removed.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t4\">4. Case Modifier Methods<\/strong><\/h4>\n<p>Similar to the Modifier methods, the Case Modifier methods also modifies the value of a string. Unlike the modifiers however, case modifier specifically modifies the case of the string.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><strong>String toLowerCase()<\/strong><\/p>\n<p>Converts all of the characters in a String to lower case applying the rules of the default locale.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>String toLowerCase(Locale locale)<\/strong><\/p>\n<p>Converts all of the characters in this String to lower case applying the rules of the specified Locale.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><strong>String toUpperCase()<\/strong><\/p>\n<p>Converts all of the characters in this String to upper case applying the rules of the default locale.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4.<\/td>\n<td><strong>String toUpperCase(Locale locale)<\/strong><\/p>\n<p>Converts all of the characters in this String to upper case applying the rules of the specified Locale.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t5\">5. Substring Methods<\/strong><\/h4>\n<p>You use\u00a0 these methods to find either find substrings within given string<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><strong>String substring(int beginIndex)<\/strong><\/p>\n<p>It finds a substring from a string starting from the given index to the end of the string. Then returns this string<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>String substring(int beginIndex, int endIndex)<\/strong><\/p>\n<p>It finds a substring from a string starting from the given index, beginIndex to the specified endIndex. Then returns this string<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><strong id=\"t6\"><br \/>\n6. Bytes and Char Methods<\/strong><\/h4>\n<p>These methods are use to retrieve char and byte related information.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><strong>byte getBytes()<\/strong><\/p>\n<p>It creates a sequence of bytes from a string by\u00a0 using the platform&#8217;s default charset, and stores the result into a new byte array. Then returns the new byte array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>byte[] getBytes(String charsetName)<\/strong><\/p>\n<p>It creates a sequence of bytes from a string using the named charset, storing the result into a new byte array. Then returns it.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><strong>void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)<\/strong><\/p>\n<p>Copies characters from this string into the destination character array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4.<\/td>\n<td><strong>char[] toCharArray()<\/strong><\/p>\n<p>It converts the string to a character array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><strong>char charAt(int index)<\/strong><\/p>\n<p>It returns the character at the given index.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t7\">7. Matching Methods<\/strong><\/h4>\n<p>These methods are used to match the string against regular expressions or other texts.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><strong>boolean matches(String regex)<\/strong><\/p>\n<p>Tells if\u00a0 a string matches the given regular expression. Returns true if it matches.Otherwise, returns false.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>boolean regionMatches(ignoreCase, toffset, String other, int ooffset, int len)<\/strong><\/p>\n<p>Checks whether two string regions are equal.\u00a0 Watch the video for the demo<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3<\/td>\n<td><strong>boolean regionMatches(int toffset, String other, int ooffset, int len)<\/strong><\/p>\n<p>Tests whether two string regions are equal. Watch the video for the demo<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h4><strong id=\"t8\">8. Misc Methods<\/strong><\/h4>\n<p>We also have other methods that does not fall into any of the categories. Hence they are miscellaneous methods. Find list of them below.<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<td class=\"ts\">1<\/td>\n<td><strong>static String valueOf(primitive data type x)<\/strong><\/p>\n<p>This method returns the string representation of the specified data type argument.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">2<\/td>\n<td><strong>int hashCode()<\/strong><\/p>\n<p>Returns a hash code for the string as integer<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">3.<\/td>\n<td><strong>String intern()<\/strong><\/p>\n<p>Returns a canonical representation for the string a particular string.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">4<\/td>\n<td><strong>int length()<\/strong><\/p>\n<p>Returns the length of this string. That is number of characters in the string<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><strong>String toString()<\/strong><\/p>\n<p>Converts a string to a string. So basically returns the same string!<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">7<\/td>\n<td><strong>static String copyValueOf(char[] data)<\/strong><\/p>\n<p>It returns a String that represents the character sequence in the given character array.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">8<\/td>\n<td><strong>static String copyValueOf(char[] data, int offset, int count)<\/strong><\/p>\n<p>It returns a String that represents the character sequence in the given character array starting from offset to the speficied count.<\/td>\n<\/tr>\n<tr>\n<td class=\"ts\">5<\/td>\n<td><strong>String concat(String str)<\/strong><\/p>\n<p>Concatenates the specified string to the end of a string. Combines the two strings together<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this lesson, we are going to learn about various String methods. If you would need to manipulate strings, then these methods are handy. &nbsp; &hellip; <\/p>\n","protected":false},"author":395,"featured_media":140,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2],"tags":[],"class_list":["post-111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java - String Methods - Java Tutorials<\/title>\n<meta name=\"description\" content=\"In this tutorial you will learn how to manipulate strings in Java using various string methods available in the String class.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java - String Methods - Java Tutorials\" \/>\n<meta property=\"og:description\" content=\"In this tutorial you will learn how to manipulate strings in Java using various string methods available in the String class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/\" \/>\n<meta property=\"og:site_name\" content=\"Java Tutorials\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-20T20:56:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-02T04:38:23+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/String-Manipulation-in-Java.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"950\" \/>\n\t<meta property=\"og:image:height\" content=\"518\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"kindsonthegenius\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"kindsonthegenius\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/\"},\"author\":{\"name\":\"kindsonthegenius\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"headline\":\"Java &#8211; String Methods\",\"datePublished\":\"2019-01-20T20:56:37+00:00\",\"dateModified\":\"2019-03-02T04:38:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/\"},\"wordCount\":1160,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/9\\\/2019\\\/01\\\/String-Manipulation-in-Java.jpg\",\"articleSection\":[\"Java Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/\",\"name\":\"Java - String Methods - Java Tutorials\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/9\\\/2019\\\/01\\\/String-Manipulation-in-Java.jpg\",\"datePublished\":\"2019-01-20T20:56:37+00:00\",\"dateModified\":\"2019-03-02T04:38:23+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\"},\"description\":\"In this tutorial you will learn how to manipulate strings in Java using various string methods available in the String class.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/9\\\/2019\\\/01\\\/String-Manipulation-in-Java.jpg\",\"contentUrl\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/wp-content\\\/uploads\\\/sites\\\/9\\\/2019\\\/01\\\/String-Manipulation-in-Java.jpg\",\"width\":950,\"height\":518,\"caption\":\"String Manipulation in Java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/23-java-string-methods\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java &#8211; String Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#website\",\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/\",\"name\":\"Java Tutorials\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/#\\\/schema\\\/person\\\/63a68934672db675ff0cd80d066510c2\",\"name\":\"kindsonthegenius\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g\",\"caption\":\"kindsonthegenius\"},\"url\":\"https:\\\/\\\/www.kindsonthegenius.com\\\/java\\\/author\\\/kindsonthegenius-2\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java - String Methods - Java Tutorials","description":"In this tutorial you will learn how to manipulate strings in Java using various string methods available in the String class.","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:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/","og_locale":"en_US","og_type":"article","og_title":"Java - String Methods - Java Tutorials","og_description":"In this tutorial you will learn how to manipulate strings in Java using various string methods available in the String class.","og_url":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/","og_site_name":"Java Tutorials","article_published_time":"2019-01-20T20:56:37+00:00","article_modified_time":"2019-03-02T04:38:23+00:00","og_image":[{"width":950,"height":518,"url":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/String-Manipulation-in-Java.jpg","type":"image\/jpeg"}],"author":"kindsonthegenius","twitter_card":"summary_large_image","twitter_misc":{"Written by":"kindsonthegenius","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/#article","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/"},"author":{"name":"kindsonthegenius","@id":"https:\/\/www.kindsonthegenius.com\/java\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"headline":"Java &#8211; String Methods","datePublished":"2019-01-20T20:56:37+00:00","dateModified":"2019-03-02T04:38:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/"},"wordCount":1160,"commentCount":0,"image":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/String-Manipulation-in-Java.jpg","articleSection":["Java Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/","url":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/","name":"Java - String Methods - Java Tutorials","isPartOf":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/#primaryimage"},"image":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/String-Manipulation-in-Java.jpg","datePublished":"2019-01-20T20:56:37+00:00","dateModified":"2019-03-02T04:38:23+00:00","author":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2"},"description":"In this tutorial you will learn how to manipulate strings in Java using various string methods available in the String class.","breadcrumb":{"@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/#primaryimage","url":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/String-Manipulation-in-Java.jpg","contentUrl":"https:\/\/www.kindsonthegenius.com\/java\/wp-content\/uploads\/sites\/9\/2019\/01\/String-Manipulation-in-Java.jpg","width":950,"height":518,"caption":"String Manipulation in Java"},{"@type":"BreadcrumbList","@id":"https:\/\/www.kindsonthegenius.com\/java\/23-java-string-methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.kindsonthegenius.com\/java\/"},{"@type":"ListItem","position":2,"name":"Java &#8211; String Methods"}]},{"@type":"WebSite","@id":"https:\/\/www.kindsonthegenius.com\/java\/#website","url":"https:\/\/www.kindsonthegenius.com\/java\/","name":"Java Tutorials","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.kindsonthegenius.com\/java\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.kindsonthegenius.com\/java\/#\/schema\/person\/63a68934672db675ff0cd80d066510c2","name":"kindsonthegenius","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3079a7f663b02e801d03cd075852a037af36bd179b5fbcd0603bae3dd7833a9b?s=96&d=mm&r=g","caption":"kindsonthegenius"},"url":"https:\/\/www.kindsonthegenius.com\/java\/author\/kindsonthegenius-2\/"}]}},"_links":{"self":[{"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/users\/395"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":4,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":143,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/posts\/111\/revisions\/143"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/media\/140"}],"wp:attachment":[{"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kindsonthegenius.com\/java\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}