{"id":73570,"date":"2022-06-23T11:16:48","date_gmt":"2022-06-23T05:46:48","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/"},"modified":"2024-10-24T19:24:38","modified_gmt":"2024-10-24T13:54:38","slug":"string-methods-java","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/","title":{"rendered":"String Methods Java: A Guide To Java Strings With Examples"},"content":{"rendered":"\n<p>A string is a sequence of characters. In <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/java-programming\" target=\"_blank\" rel=\"noreferrer noopener\">Java Programming<\/a>, strings are widely used and treated as objects, and string in Java can not be changed once it has been created. There are several methods in Java that assist in performing operations in a string called String functions. In this article, we will explore various string methods along with detailed examples.&nbsp;So, let's get started.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java-strings\"><strong>Java Strings&nbsp;<\/strong><\/h2>\n\n\n\n<p>Strings in Java can be created using a character, object, or literal. There are numerous Java string methods such as equals(), split(), replace(), length(), and so on. An array of values represents a string. Serializable, Comparable, and CharSequence implement the class. You can create a string object using the java.lang.String class. It allows users to manipulate strings.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">char[] ch={'j','a','v','a','t','p','o','i','n','t'};  \nString s=new String(ch);  \n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"example-of-java-string\"><strong>Example of Java String<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>public class StringExample{    \npublic static void main(String args&#91;]){    \nString s1=\"java\";\/\/creating string by Java string literal    \nchar ch&#91;]={'s','t','r','i','n','g','s'};    \nString s2=new String(ch);\/\/converting char array to string    \nString s3=new String(\"example\");\/\/creating Java string by new keyword    \nSystem.out.println(s1);    \nSystem.out.println(s2);    \nSystem.out.println(s3);    \n}}\n<\/code><\/pre>\n\n\n\n<p>When you run it, it will give the following output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">java\nstrings\nexample\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"creating-a-java-string\"><strong>Creating a Java String&nbsp;<\/strong><\/h2>\n\n\n\n<p>A Java string can be created in two ways:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using string literal<\/li>\n\n\n\n<li>Using a new keyword&nbsp;<\/li>\n<\/ul>\n\n\n\n<p>String Literal- In Java, a string literal is created using double-quotes. For example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">String str1=\"welcome\"; \nString str2 = \"welcome\"; (It does not create new instance)\n<\/pre>\n\n\n\n<p>The string literal in the above-given example is \u2018welcome,\u2019 and the compiler creates a String object. If an object already exists, it would simply assign the old object to the new instance. There are two string instances - str1 and str2 and the compiler assigned the value \u2018welcome\u2019 to both the instances. But if we want to create two different objects using the exact string. For that, we need to create a string using a new keyword.&nbsp;<\/p>\n\n\n\n<p>New keyword- Using literal, the compiler only created one object when we assigned the same object using two literals. To overcome this, we can create strings in this way:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">String str1 = new String(\"Welcome\");\nString str2 = new String(\"Welcome\");\n<\/pre>\n\n\n\n<p>In this example, the compiler will create two objects with one reference variable in this example. The value \u2018welcome\u2019 will be placed in the constant pool.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"java-string-methods\"><strong>Java String Methods<\/strong><\/h2>\n\n\n\n<p>We have enlisted a few Java string methods that can be further explained individually. Here are they -<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>char charAt(int index)- <\/strong>It returns the character value at the particular index. The index value lie between 0 to length () - 1.&nbsp;<\/li>\n\n\n\n<li><strong>String substring(int beginIndex)-<\/strong> It returns a substring from a specified index.<\/li>\n\n\n\n<li><strong>int length()-<\/strong> It returns string length.<\/li>\n\n\n\n<li><strong>String substring(int beginIndex, int endIndex)-<\/strong> It returns substring for begin and end index.<\/li>\n\n\n\n<li><strong>static String format(Locale l, String format, Object... args)-<\/strong> It returns a formatted string corresponding to the given locale.&nbsp;<\/li>\n\n\n\n<li><strong>boolean equals(Object obj)- <\/strong>It returns a true value if the string matches the specified, or else it gives a false if it doesn\u2019t.<\/li>\n\n\n\n<li><strong>boolean equalsIgnoreCase(String string)-<\/strong> It returns a value based on a case-sensitive comparison of the strings.<\/li>\n\n\n\n<li><strong>boolean startsWith(String prefix)-<\/strong> It returns a true or false value depending on the string's specified prefix.<\/li>\n\n\n\n<li><strong>boolean endsWith(String suffix)-<\/strong> It checks if the particular string ends with the specified suffix.<\/li>\n\n\n\n<li><strong>int hashCode()-<\/strong> It returns the hash code of the string.<\/li>\n\n\n\n<li><strong>String substring(int beginIndex, int endIndex)-<\/strong> It returns the substring that begins with the character at beginIndex and ends with endIndex.<\/li>\n\n\n\n<li><strong>String intern()-<\/strong> It returns the canonical form of the given String.<\/li>\n\n\n\n<li><strong>String toLowerCase()- It returns a <\/strong>string with characters in lowercase.<\/li>\n\n\n\n<li><strong>String toUpperCase()- It returns a <\/strong>string with characters in uppercase.<\/li>\n\n\n\n<li><strong>String toLowerCase(Locale l)- <\/strong>It returns a string with a character in lowercase with a specified locale.<\/li>\n\n\n\n<li><strong>String toUpperCase(Locale l)-<\/strong> It returns a string with a character in uppercase with a specified locale.<\/li>\n\n\n\n<li><strong>subSequence()- <\/strong>It returns a sub sequence from the string.&nbsp;<\/li>\n\n\n\n<li><strong>toCharArray()-<\/strong> It converts the string to a character array.<\/li>\n\n\n\n<li><strong>isEmpty()- <\/strong>It checks if a given string is empty or not.&nbsp;<\/li>\n\n\n\n<li><strong>String Concat(String str)-<\/strong> It returns the value by linking together the strings.<\/li>\n\n\n\n<li><strong>String replace(char old, char new)-<\/strong> It replaces the specified char value at all instances with the new one.<\/li>\n\n\n\n<li><strong>String replace(CharSequence old, CharSequence new)-<\/strong> It replaces the value of a given CharSequence with a new one across all instances.&nbsp;<\/li>\n\n\n\n<li><strong>String trim()-<\/strong> It eliminates the starting and ending tails of the string.<\/li>\n\n\n\n<li><strong>String matches()-<\/strong> It checks if the specified string matches the regex.<\/li>\n\n\n\n<li><strong>static String valueOf(int value)-<\/strong> It is an overloaded method to convert the given type into a string.&nbsp;&nbsp;<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"examples-of-string-functions\"><strong>Examples of String Functions<\/strong><\/h2>\n\n\n\n<p>Let us check some examples of string functions in Java.&nbsp;<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>How to convert a string to lowercase?<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public class StringLowerExercise{\npublic static void main(String args&#91;]){\nString s1=\"HELLO HOW Are You TODAY?\u201d;\nString s1lower=s1.toLowerCase();\nSystem.out.println(s1lower);}\n}<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>How to check if two strings are equal?<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public class EqualsExercise{\npublic static void main(String args&#91;]){\nString s1=\"Hi\";\nString s2=\"Hey\";\nString s3=\"Hello\";\nSystem.out.println(s1.equalsIgnoreCase(s2));   \/\/ returns true\nSystem.out.println(s1.equalsIgnoreCase(s3));   \/\/ returns false\n}\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>How to check if a string is empty?<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public class IsEmptyExercise{\npublic static void main(String args&#91;]){\nString s1=\"\";\nString s2=\"Hello\";\nSystem.out.println(s1.isEmpty());      \/\/ true\nSystem.out.println(s2.isEmpty());      \/\/ false\n}}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>How to replace a part of a string?<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ReplaceExercise{\npublic static void main(String args&#91;]){\nString s1=\"hello how are you today\";\nString replaceString=s1.replace('h','t');\nSystem.out.println(replaceString); }}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>How to join two Java strings?<\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>class Main {\n  public static void main(String&#91;] args) {\n\n    \/\/ create first string\n    String first = \"Java \";\n    System.out.println(\"First String: \" + first);\n\n    \/\/ create second\n    String second = \"Programming\";\n    System.out.println(\"Second String: \" + second);\n\n    \/\/ join two strings\n    String joinedString = first.concat(second);\n    System.out.println(\"Joined String: \" + joinedString);\n  }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion&nbsp;<\/strong><\/h2>\n\n\n\n<p>Java strings are backed by a char array internally, giving them the immutable characteristic. Strings are stored in a heap along with all objects in Java. There are facts associated with string class and the functions and methods we explained above. A good developer should be adept at string manipulation, a crucial aspect of any programming language.&nbsp;Learn all about Java and other such popular programming languages for free at <a href=\"https:\/\/www.mygreatlearning.com\/academy\" target=\"_blank\" rel=\"noreferrer noopener\">Great Learning Academy<\/a>.<\/p>\n\n\n\n<p>Recommended Articles<\/p>\n\n\n\n<ul class=\"wp-block-list is-style-styled\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/data-structures-using-java\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Data Structures &amp; Algorithms Using Java \u2013 A Beginners Guide<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-interview-questions\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Java Interview Questions and Answers for Freshers and Experienced in 2023<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-array-length\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>How to find Array Length in Java<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/reverse-linked-list\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>How to Reverse Linked List in Java?<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-operators\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>What are Java Operators? Types, Examples and more<\/strong><\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-is-file-handling-in-java\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>What is File Handling in Java?<\/strong><\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A string is a sequence of characters. In Java Programming, strings are widely used and treated as objects, and string in Java can not be changed once it has been created. There are several methods in Java that assist in performing operations in a string called String functions. In this article, we will explore various [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":73576,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36826],"content_type":[],"class_list":["post-73570","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-java"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>String Methods Java: A Guide To Java Strings With Examples<\/title>\n<meta name=\"description\" content=\"Strings are a widely used sequence of characters in Java. Learn all about String Methods Java in this blog along with detailed examples.\" \/>\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.mygreatlearning.com\/blog\/string-methods-java\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"String Methods Java: A Guide To Java Strings With Examples\" \/>\n<meta property=\"og:description\" content=\"Strings are a widely used sequence of characters in Java. Learn all about String Methods Java in this blog along with detailed examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-23T05:46:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-24T13:54:38+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"853\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"String Methods Java: A Guide To Java Strings With Examples\",\"datePublished\":\"2022-06-23T05:46:48+00:00\",\"dateModified\":\"2024-10-24T13:54:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/\"},\"wordCount\":917,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/computer-2583383_1280.jpg\",\"keywords\":[\"java\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/\",\"name\":\"String Methods Java: A Guide To Java Strings With Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/computer-2583383_1280.jpg\",\"datePublished\":\"2022-06-23T05:46:48+00:00\",\"dateModified\":\"2024-10-24T13:54:38+00:00\",\"description\":\"Strings are a widely used sequence of characters in Java. Learn all about String Methods Java in this blog along with detailed examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/computer-2583383_1280.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/computer-2583383_1280.jpg\",\"width\":1280,\"height\":853,\"caption\":\"string methods java\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/string-methods-java\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"String Methods Java: A Guide To Java Strings With Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"String Methods Java: A Guide To Java Strings With Examples","description":"Strings are a widely used sequence of characters in Java. Learn all about String Methods Java in this blog along with detailed examples.","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.mygreatlearning.com\/blog\/string-methods-java\/","og_locale":"en_US","og_type":"article","og_title":"String Methods Java: A Guide To Java Strings With Examples","og_description":"Strings are a widely used sequence of characters in Java. Learn all about String Methods Java in this blog along with detailed examples.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2022-06-23T05:46:48+00:00","article_modified_time":"2024-10-24T13:54:38+00:00","og_image":[{"width":1280,"height":853,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"String Methods Java: A Guide To Java Strings With Examples","datePublished":"2022-06-23T05:46:48+00:00","dateModified":"2024-10-24T13:54:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/"},"wordCount":917,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg","keywords":["java"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/","url":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/","name":"String Methods Java: A Guide To Java Strings With Examples","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg","datePublished":"2022-06-23T05:46:48+00:00","dateModified":"2024-10-24T13:54:38+00:00","description":"Strings are a widely used sequence of characters in Java. Learn all about String Methods Java in this blog along with detailed examples.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg","width":1280,"height":853,"caption":"string methods java"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/string-methods-java\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"String Methods Java: A Guide To Java Strings With Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg",1280,853,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280-1024x682.jpg",1024,682,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg",1280,853,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280.jpg",1280,853,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280-640x853.jpg",640,853,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280-96x96.jpg",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/computer-2583383_1280-150x100.jpg",150,100,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"A string is a sequence of characters. In Java Programming, strings are widely used and treated as objects, and string in Java can not be changed once it has been created. There are several methods in Java that assist in performing operations in a string called String functions. In this article, we will explore various&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/73570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=73570"}],"version-history":[{"count":6,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/73570\/revisions"}],"predecessor-version":[{"id":104513,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/73570\/revisions\/104513"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/73576"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=73570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=73570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=73570"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=73570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}