{"id":89343,"date":"2024-03-11T18:00:41","date_gmt":"2024-03-11T12:30:41","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=89343"},"modified":"2024-03-11T18:00:41","modified_gmt":"2024-03-11T12:30:41","slug":"java-string-concat-method","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/","title":{"rendered":"Java String concat() Method with Examples"},"content":{"rendered":"<p>String concatenation is an essential operation in laptop programming and refers to the method of combining or becoming a member of or more strings together to create a brand new string. This operation permits you to build longer strings by appending one or more strings to an existing one.<\/p>\n<p>In lots of programming languages, along with Java, Python, C++, and many others, there are particular techniques or operators for acting string concatenation.<\/p>\n<h2>String Concatenation in Java<\/h2>\n<p>In Java, String concatenation paperwork is a new String that is the mixture of a couple of strings.<\/p>\n<p><strong>There are two approaches to concatenating strings in Java:<\/strong><\/p>\n<p>By + (String concatenation) operator<br \/>\nBy concat() method<\/p>\n<h3>Difference between concat() and + operator:<\/h3>\n<p>Strings are interpreted as character arrays. The difference between a string and a string is that the string ends with the special character &#8220;\\0&#8221;. Since arrays are immutable (can&#8217;t grow), strings are also immutable. When a change is made to a string, a new string is created. Connectivity is the process of establishing an end-to-end connection.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">  class TestStringConcatenation1{  \n public static void main(String args[]){  \n String s=\"Tech\"+\" Vidvan\";  \n   System.out.println(s);\/\/TechVidvan \n }  \n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nTechVidvan<\/p>\n<h3>Java String Concatenation by concat() method<\/h3>\n<p>The String concat() technique concatenates the specified string to the end of current string.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<p>public String concat(String another)<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">  class TestStringConcatenation3{  \n public static void main(String args[]){  \n   String s1=\"Tech\";  \n  String s2=\"Vidvan\";  \n  String s3=s1.concat(s2);  \n   System.out.println(s3);\/\/TechVidvan\n  }  \n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nTechVidvan<\/p>\n<p>The above Java program concatenates two String objects, s1 and s2, using the concat() method and stores the result in the s3 object.<\/p>\n<h3>String concatenation using StringBuilder class<\/h3>\n<p>StringBuilder is a class that provides an Append() method to perform concatenation operations. The Append() method accepts parameters of various types such as Objects, StringBuilder, int, char, CharSequence, boolean, float, and double. StringBuilder is the most popular and fastest way to concatenate strings in Java. It is a mutable class, meaning that the values \u200b\u200bstored in the StringBuilder object can be modified or modified.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">open   course  StrBuilder   {    \/* Driver Code *\/     open   inactive  void main(String args[])    {    StringBuilder s1 =  modern  StringBuilder(\"Tech\"); \/\/String 1    StringBuilder s2 =  unused  StringBuilder(\"Vidvan\"); \/\/String 2    StringBuilder s = s1.append(s2); \/\/String 3 to store the result    System.out.println(s.toString()); \/\/ Shows  result    }   }<\/pre>\n<p><strong>Output:<\/strong><br \/>\nTechVidvan<\/p>\n<p>In the above code snippet, s1, s2 and s are declared as objects of StringBuilder class. s stores the result of concatenation of s1 and s2 using append() method.<\/p>\n<h3>String concatenation using format() method<\/h3>\n<p>String.format() strategy permits to concatenate numerous strings utilizing arrange specifier like %s taken after by the string values or objects.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">     public class StrFormat  \n{  \n  \/* Driver Code *\/  \n    public static void main(String args[])  \n   {  \n        String s1 = new String(\"Tech\");    \/\/String 1  \n       String s2 = new String(\" Vidvan\");    \/\/String 2  \n        String s = String.format(\"%s%s\",s1,s2);   \/\/String 3 to store the result  \n            System.out.println(s.toString());  \/\/Displays result  \n    }  \n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nTechVidvan<\/p>\n<p>String.format() strategy permits to concatenate numerous strings utilizing arrange specifier like %s take Right here, the String contraptions are relegated the concatenated conclusion result of Strings s1 and s2 the utilization of String.Format() approach. Organize () acknowledges parameters as arranged specifiers taken after through String things or values.<\/p>\n<h3>String concatenation using String.join() method.<\/h3>\n<p>The String.Join() approach is to be had in Java model 8 and all the above variations. String.Join() technique accepts arguments first, a separator and an array of String items.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">    public class StrJoin  \n{  \n    \/* Driver Code *\/  \n    public static void main(String args[])  \n    {  \n        String s1 = new String(\"Tech\");    \/\/String 1  \n        String s2 = new String(\"Vidvan\");    \/\/String 2  \n        String s = String.join(\"\",s1,s2);   \/\/String 3 to store the result  \n            System.out.println(s.toString());  \/\/Displays result  \n    }  \n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nTechVidvan<\/p>\n<p>In the above code snippet, the String object s stores the result of String.join(&#8220;&#8221;,s1,s2) method. A separator is specified inside quotation marks followed by the String objects or array of String object.<\/p>\n<h3>String concatenation using StringJoiner class<\/h3>\n<p>StringJoiner magnificence has all the functionalities of String.Join() approach. Earlier, its constructor also can receive optional arguments, prefix and suffix.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class StrJoiner  \n{  \n    \/* Driver Code *\/  \n    public static void main(String args[])  \n    {  \n        StringJoiner s = new StringJoiner(\", \");   \/\/StringJoiner object  \n       s.add(\"Tech\");    \/\/String 1   \n        s.add(\"Vidvan\");    \/\/String 2  \n        System.out.println(s.toString());  \/\/Displays result  \n    }  \n}<\/pre>\n<p><strong>Output:<\/strong><br \/>\nTech,Vidvan<\/p>\n<p>In the above script, a StringJoiner object is represented, and the StringJoiner() constructor accepts a delimiter value. Delimiters are special inside quotes. The add() method adds the string beyond the parameter.<\/p>\n<h3>Conclusion<\/h3>\n<p>The concat() method performs higher than the \u201c+\u201d operator. The latter usually creates a new string, no matter the length of the string. Additionally, we need to take into account that the concat() method simplest creates a new string whilst the string to be appended has a period more than zero.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>String concatenation is an essential operation in laptop programming and refers to the method of combining or becoming a member of or more strings together to create a brand new string. This operation permits&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":89345,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[183],"tags":[296,5407,5408,5409,250,5410,5411,5412],"class_list":["post-89343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java","tag-java","tag-java-string-concat","tag-java-string-concat-method","tag-java-string-concat-method-with-examples","tag-learn-java","tag-string-concat","tag-string-concat-method","tag-string-concat-method-in-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Java String concat() Method with Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"This Java String concat() operation permits you to build longer strings by appending one or more strings to an existing one.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Java String concat() Method with Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"This Java String concat() operation permits you to build longer strings by appending one or more strings to an existing one.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-11T12:30:41+00:00\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Java String concat() Method with Examples - TechVidvan","description":"This Java String concat() operation permits you to build longer strings by appending one or more strings to an existing one.","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:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/","og_locale":"en_US","og_type":"article","og_title":"Java String concat() Method with Examples - TechVidvan","og_description":"This Java String concat() operation permits you to build longer strings by appending one or more strings to an existing one.","og_url":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2024-03-11T12:30:41+00:00","author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Java String concat() Method with Examples","datePublished":"2024-03-11T12:30:41+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/"},"wordCount":597,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/#primaryimage"},"thumbnailUrl":"","keywords":["java","java string concat()","java string concat() method","java string concat() method with examples","Learn Java","string concat()","string concat() method","string concat() method in java"],"articleSection":["Java Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/","url":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/","name":"Java String concat() Method with Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/#primaryimage"},"thumbnailUrl":"","datePublished":"2024-03-11T12:30:41+00:00","description":"This Java String concat() operation permits you to build longer strings by appending one or more strings to an existing one.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/java-string-concat-method\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Java String concat() Method with Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/89343","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=89343"}],"version-history":[{"count":0,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/89343\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=89343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=89343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=89343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}