{"id":78695,"date":"2022-08-09T15:27:30","date_gmt":"2022-08-09T09:57:30","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/"},"modified":"2024-09-12T14:11:33","modified_gmt":"2024-09-12T08:41:33","slug":"java-stringbuilder","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/","title":{"rendered":"Java StringBuilder Class: Methods, Examples and more"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"introduction-to-java-stringbuilder\"><strong>Introduction to Java StringBuilder<\/strong><\/h2>\n\n\n\n<p>StringBuilder is a Java Class used to create mutable or successors that can be modified with characters. The StringBuilder class is similar to another <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/class-in-java\" target=\"_blank\" rel=\"noreferrer noopener\">class in java<\/a>, StringBuffer, but is non-synchronized. The StringBuilder class doesn\u2019t provide synchronization, and this is why Java StringBuilder is more suitable to work with than StringBuffer, as it works with a single thread.&nbsp;<\/p>\n\n\n\n<p>The StringBuilder class provides high performance compared with other string classes, and it is not thread-safe and provides other methods for various purposes. The heap section of the memory allocates memory in the StringBuilder class, and the StringBuilder class is preferred when we manipulate characters in our string.&nbsp;<\/p>\n\n\n\n<p>In this article, we\u2019ll understand how you can use the StringBuilder class effectively with some examples of this class.&nbsp;<\/p>\n\n\n\n<p><strong>Syntax<\/strong><\/p>\n\n\n\n<p>Let us see the syntax of the StringBuilder class below to understand the format of code better to be used in actual <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/java-programming\" target=\"_blank\" rel=\"noreferrer noopener\">Java programming<\/a>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npublic final class StringBuilder\nextends Object\nimplements Serializable, CharSequence\n<\/pre><\/div>\n\n\n<p>In this syntax, the StringBuilder class extend a public class named \u2018Object\u2019 where two interfaces are implemented. You can use Serializable or CharSequence interfaces or any interfaces you want to apply in this class. These interfaces are used to implement various operations on the character of the sequence of our string.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"important-constructors-of-stringbuilder-class\"><strong>Important Constructors of StringBuilder class<\/strong><\/h2>\n\n\n\n<p>The StringBuilder class provides several types of <a href=\"https:\/\/www.mygreatlearning.com\/blog\/constructor-in-java\/\">constructors<\/a> used for converting a sequence of characters, the format of characters, and the configuration of some properties of StringBuilder such as size, etc. Here are the essential constructors of the StringBuilder class discussed below:<\/p>\n\n\n\n<p><strong>1. StringBuilder<\/strong>: This constructor is used to create a blank string builder. Initially, the capacity of this builder is set to 16 characters.<\/p>\n\n\n\n<p><strong>2. StringBuilder(int capacity):<\/strong> This constructor also creates an empty builder, but you can specify the builder's capacity.&nbsp;<\/p>\n\n\n\n<p><strong>3. StringBuilder(CharSequence):<\/strong> The characters in this builder are created with specified arguments. The CharSequence is used for the sequence of characters in the StringBuilder.<\/p>\n\n\n\n<p><strong>4. StringBuilder(string):<\/strong> This constructor is used to construct a string builder with a given string.&nbsp;<\/p>\n\n\n\n<p>Check out some of the important questions on StringBuilder in&nbsp;<a href=\"https:\/\/www.mygreatlearning.com\/blog\/java-interview-questions\/\" target=\"_blank\" rel=\"noreferrer noopener\">java interview questions<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"methods-of-stringbuilder-class\"><strong>Methods of StringBuilder class<\/strong><\/h2>\n\n\n\n<p>The StringBuilder class uses various methods. These methods are used to perform different operations on the StringBuilder class. In this section, we will discuss the methods of the StringBuilder class below:<\/p>\n\n\n\n<p><strong>1. append():<\/strong> This method is used when we need to append a new sequence in the existing sequence of characters in the StringBuilder class.&nbsp;<\/p>\n\n\n\n<p>Syntax to use append() method:<\/p>\n\n\n\n<p>StringBuilder.append(datatype s)<\/p>\n\n\n\n<p>In the above syntax, s is provided as an argument of specified type - \u2018datatype\u2019. The Datatype is String in this case as we are appending string sequence to the existing String.<\/p>\n\n\n\n<p><strong>2. reverse():<\/strong> As the name suggests, the reverse method is used to reverse the sequence of characters of the StringBuilder string.&nbsp;<\/p>\n\n\n\n<p>Syntax for reverse() method:<\/p>\n\n\n\n<p>public java.lang.AbstractStringBuilder reverse( )<\/p>\n\n\n\n<p><strong>3. charAt():<\/strong> This method is useful in the situation when we want a specific character at an index value. We need to give the index value of the character from the string, and it will return that character.&nbsp;<\/p>\n\n\n\n<p>Syntax for charAt() method:<\/p>\n\n\n\n<p>public char charAt(index_no)<\/p>\n\n\n\n<p>In the above syntax, index_no is used as an argument where we will provide the index of the StringBuilder sequence that will return the character at that index number.&nbsp;<\/p>\n\n\n\n<p><strong>4. capacity():<\/strong> To find the initial capacity of the StringBuilder object, the capacity() method is used. However, the default capacity of the StringBuilder class is 16 bytes.&nbsp;&nbsp;<\/p>\n\n\n\n<p>Syntax to use capacity() method:<\/p>\n\n\n\n<p>public int capacity()<\/p>\n\n\n\n<p>This syntax is used to get the capacity of the StringBuilder sequence.&nbsp;<\/p>\n\n\n\n<p><strong>5. lastIndexof():<\/strong> The last index of any particular StringBuilder sequence can be found using this method.&nbsp;<\/p>\n\n\n\n<p>Syntax of lastIndexof() method:<\/p>\n\n\n\n<p>public int lastIndexof(stringName)<\/p>\n\n\n\n<p>The above syntax takes one parameter as the string's name and returns the string's last index.&nbsp;<\/p>\n\n\n\n<p><strong>6. isEmpty():<\/strong> This method is used to check whether the StringBuilder object is empty.&nbsp;<\/p>\n\n\n\n<p>Syntax of isEmpty() method:<\/p>\n\n\n\n<p>public StringBuilder.isEmpty()<\/p>\n\n\n\n<p>It doesn\u2019t require any parameter to be passed and returns True if there is no string and False if a String is present. So, the return type of this method is Boolean.&nbsp;<\/p>\n\n\n\n<p><strong>7. substring():<\/strong> substring() method is used to find the substring of the StringBuilder sequence.&nbsp;<\/p>\n\n\n\n<p>The syntax of the substring() method is as follows:<\/p>\n\n\n\n<p>public StringBuilder.substring(index_start, index_end+1)<\/p>\n\n\n\n<p>The above syntax requires two parameters as the starting and ending index of the sequence of StringBuilder. It returns the string of characters for the sequence according to the index number provided in the method.&nbsp;<\/p>\n\n\n\n<p><strong>8. length():<\/strong> This method is used to find the length of the sequence of StringBuilder. The syntax to use the length() method is as follows:<\/p>\n\n\n\n<p>public StringBuilder.length()<\/p>\n\n\n\n<p>The above syntax doesn\u2019t need any parameter, and it returns the length of the StringBuilder sequence.&nbsp;<\/p>\n\n\n\n<p><strong>9. indexof():<\/strong> This method is used when we need to find the first index of a given string in the StringBuilder sequence. In the absence of a string, it returns -1.<\/p>\n\n\n\n<p>Syntax to use indexof() method:<\/p>\n\n\n\n<p>public int indexof(StringName)<\/p>\n\n\n\n<p>The above syntax takes one parameter as the name of the string and returns the first index value of the string and -1 if the string is not present.&nbsp;<\/p>\n\n\n\n<p><strong>10. delete():<\/strong> When we don\u2019t need a particular sequence from the StringBuilder sequence, we will use the delete() method.&nbsp;<\/p>\n\n\n\n<p>Syntax to use delete() method:<\/p>\n\n\n\n<p>public StringBuilder.delete(index_start, index_end+1)<\/p>\n\n\n\n<p>The above syntax requires two parameters as index numbers and returns the StringBuilder reference.&nbsp;<\/p>\n\n\n\n<p><strong>Examples of StringBuilder: <\/strong>Let us see some examples better to understand the methods of the StringBuilder class in Java:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stringbuilder-append-method\"><strong>StringBuilder append() method<\/strong><\/h2>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class AppendExample{\npublic static void main(String args&#091;]){\nStringBuilder mystring = new StringBuilder(\u201cLearn\u201d);\nmystring.append(\u201c Java StringBuilder\u201d);\nSystem.out.println(mystring);\nmystring.append(\u201c from GLA\u201d);\nSystem.out.println(mystring);\n}\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>Learn Java StringBuilder<\/p>\n\n\n\n<p>Learn Java StringBuilder from GLA<\/p>\n\n\n\n<p>In the above program, the String \u2018mystring\u2019 is appended with a substring. So the main string and substring are joined as an output.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stringbuilder-insert-method\"><strong>StringBuilder insert() method<\/strong><\/h2>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class InsertMethodEg{\npublic static void main(String args&#091;]){\nStringBuilder mystring = new StringBuilder(\u201cLearn\u201d);\nmystring.insert(2, \u201cString\u201d);\nSystem.out.println(mystring);\n}\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>LeStringarn<\/p>\n\n\n\n<p>In the above code, we first declared a string with the name \u2018mystring\u2019 and then inserted another substring at the specified index of the main string.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stringbuilder-replace-method\"><strong>StringBuilder replace() method<\/strong><\/h2>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ReplaceMethodEg{\npublic static void main(String args&#091;]){\nStringBuilder mystring = new StringBuilder(\u201cGreatLearning\u201d);\nmystring.replace(10,14,\u201dStringBuilder\u201d);\nSystem.out.println(mystring);\n}\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>GreatLearnStringBuilder<\/p>\n\n\n\n<p>The above program replaces the substring specified with index numbers from the main string with another substring. This way, you can replace the characters or the whole string using the index number of the main string.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stringbuilder-delete-method\"><strong>StringBuilder delete() method<\/strong><\/h2>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class DeleteMethodEg{\npublic static void main (String args&#091;]){\nStringBuilder mystring = new StringBuilder(\u201cGreatLearning\u201d);\nmystring.delete(0,5);\nSystem.out.println(mystring);\n}\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>Learning<\/p>\n\n\n\n<p>The above code is used to delete a sequence of characters from the string based on the specified indexes. In this example, we specified the index number from 0 to 5, which will remove the string characters on the index 0 to 4 only and return the remaining string.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stringbuilder-reverse-method\"><strong>StringBuilder reverse() method<\/strong><\/h2>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ReverseMethodEg{\npublic static void main(String args&#091;]){\nStringBuilder mystring = new StringBuilder(\u201cGreatLearning\u201d);\nmystring.reverse();\nSystem.out.println(mystring);\n}\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>gninraeLtaerG<\/p>\n\n\n\n<p>The reverse method is used to reverse the main string. Here in our example, we created a string with the value \u2018GreatLearning\u2019 in which the reverse function is used that reverses the string in our output.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stringbuilder-capacity-method\"><strong>StringBuilder capacity() method<\/strong><\/h2>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CapacityMethodEg{\npublic static void main(String args&#091;]){\nStringBuilder mystring = new StringBuilder();\nmystring.append(\u201cGreat Learning\u201d);\nSystem.out.println(mystring);\nSystem.out.println(\u201cThe capacity of mystring is: \u201d+ mystring.capacity());\n}\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>Great Learning<\/p>\n\n\n\n<p>The capacity of mystring is: 16<\/p>\n\n\n\n<p>In the above code, we used the capacity() method of our StringBuilder class that will return the current capacity of the string. The default capacity for any string is 16 bytes which increases when the number of characters increases more than 16 with the formula n*2+2.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"stringbuilder-ensurecapacity-method\"><strong>StringBuilder ensureCapacity() method<\/strong><\/h2>\n\n\n\n<p>Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class AnotherCapacityEg{\npublic static void main(String args&#091;]){\nStringBuilder mystring = new StringBuilder();\nmystring.append(\u201cGreat learning\u201d);\nSystem.out.println(\u201cThe capacity of the string is: \u201c + mystring.capacity());\nmystring.append(\u201cAcademy\u201d);\nSystem.out.println(\u201cThe capacity of the string is: \u201d + mystring.capacity());\nmystring.ensureCapacity(15);\nSystem.out.println(\u201cNow the capacity of the string is same as: \u201c + mystring.capacity());\nmystring.ensureCapacity(44);\nSystem.out.println(\u201cThe capacity of the string is now: \u201d + mystring.capacity());\n}\n}<\/code><\/pre>\n\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<p>The capacity of the string is: 16<\/p>\n\n\n\n<p>The capacity of the string is: 34<\/p>\n\n\n\n<p>Now the capacity of the string is the same as: 34<\/p>\n\n\n\n<p>The capacity of the string is now: 70<\/p>\n\n\n\n<p>In this example, the ensureCapacity() method is used to ensure that the capacity of the string is minimum before we perform more operations on that string. It is essential to know the capacity of the string before performing any operation.&nbsp;<\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-java-programming\" class=\"courses-cta-title-link\">Java Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Learn Java the right way! Our course teaches you essential programming skills, from coding basics to complex projects, setting you up for success in the tech industry.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>16.05 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>3 Projects<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-java-programming\" class=\"courses-cta-button\">\n                Learn Java Programming\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>This is all about the Java StringBuilder class, where we have seen the methods that can be used in this class. We have looked at examples of some of these methods. The Java StringBuilder class has various methods to be used in Java, which are helpful for different scenarios. However, the methods apply to the Strings of characters.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction to Java StringBuilder StringBuilder is a Java Class used to create mutable or successors that can be modified with characters. The StringBuilder class is similar to another class in java, StringBuffer, but is non-synchronized. The StringBuilder class doesn\u2019t provide synchronization, and this is why Java StringBuilder is more suitable to work with than StringBuffer, [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":78780,"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-78695","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>Java StringBuilder Class: Methods, Examples and more<\/title>\n<meta name=\"description\" content=\"In this blog post, we&#039;ll take a closer look at Java StringBuilder, how it works, and the different methods of the StringBuilder 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.mygreatlearning.com\/blog\/java-stringbuilder\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java StringBuilder Class: Methods, Examples and more\" \/>\n<meta property=\"og:description\" content=\"In this blog post, we&#039;ll take a closer look at Java StringBuilder, how it works, and the different methods of the StringBuilder class.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/\" \/>\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-08-09T09:57:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-09-12T08:41:33+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"1080\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Java StringBuilder Class: Methods, Examples and more\",\"datePublished\":\"2022-08-09T09:57:30+00:00\",\"dateModified\":\"2024-09-12T08:41:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/\"},\"wordCount\":1362,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/C-10.png\",\"keywords\":[\"java\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/\",\"name\":\"Java StringBuilder Class: Methods, Examples and more\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/C-10.png\",\"datePublished\":\"2022-08-09T09:57:30+00:00\",\"dateModified\":\"2024-09-12T08:41:33+00:00\",\"description\":\"In this blog post, we'll take a closer look at Java StringBuilder, how it works, and the different methods of the StringBuilder class.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/C-10.png\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/C-10.png\",\"width\":1920,\"height\":1080,\"caption\":\"Java StringBuilder\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/java-stringbuilder\\\/#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\":\"Java StringBuilder Class: Methods, Examples and more\"}]},{\"@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":"Java StringBuilder Class: Methods, Examples and more","description":"In this blog post, we'll take a closer look at Java StringBuilder, how it works, and the different methods of the StringBuilder 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.mygreatlearning.com\/blog\/java-stringbuilder\/","og_locale":"en_US","og_type":"article","og_title":"Java StringBuilder Class: Methods, Examples and more","og_description":"In this blog post, we'll take a closer look at Java StringBuilder, how it works, and the different methods of the StringBuilder class.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/","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-08-09T09:57:30+00:00","article_modified_time":"2024-09-12T08:41:33+00:00","og_image":[{"width":1920,"height":1080,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10.png","type":"image\/png"}],"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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Java StringBuilder Class: Methods, Examples and more","datePublished":"2022-08-09T09:57:30+00:00","dateModified":"2024-09-12T08:41:33+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/"},"wordCount":1362,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10.png","keywords":["java"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/","url":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/","name":"Java StringBuilder Class: Methods, Examples and more","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10.png","datePublished":"2022-08-09T09:57:30+00:00","dateModified":"2024-09-12T08:41:33+00:00","description":"In this blog post, we'll take a closer look at Java StringBuilder, how it works, and the different methods of the StringBuilder class.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10.png","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10.png","width":1920,"height":1080,"caption":"Java StringBuilder"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/java-stringbuilder\/#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":"Java StringBuilder Class: Methods, Examples and more"}]},{"@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\/08\/C-10.png",1920,1080,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10-150x150.png",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10-300x169.png",300,169,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10-768x432.png",768,432,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10-1024x576.png",1024,576,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10-1536x864.png",1536,864,true],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10.png",1920,1080,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10-640x853.png",640,853,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10-96x96.png",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/08\/C-10-150x84.png",150,84,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":"Introduction to Java StringBuilder StringBuilder is a Java Class used to create mutable or successors that can be modified with characters. The StringBuilder class is similar to another class in java, StringBuffer, but is non-synchronized. The StringBuilder class doesn\u2019t provide synchronization, and this is why Java StringBuilder is more suitable to work with than StringBuffer,&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/78695","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=78695"}],"version-history":[{"count":28,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/78695\/revisions"}],"predecessor-version":[{"id":112387,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/78695\/revisions\/112387"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/78780"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=78695"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=78695"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=78695"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=78695"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}