tag:blogger.com,1999:blog-4775830397192165042.post1626011429110085184..comments2024-03-15T21:02:56.637-07:00Comments on Java Journal: Difference between concat() and + (String concatenation operator)Unknownnoreply@blogger.comBlogger5125tag:blogger.com,1999:blog-4775830397192165042.post-74199866654271521442015-05-25T19:33:02.170-07:002015-05-25T19:33:02.170-07:00Abhishek second+"nothing" is treated as ...Abhishek second+"nothing" is treated as one method argument not as two different method arguments.sendy19https://www.blogger.com/profile/10393172881250322418noreply@blogger.comtag:blogger.com,1999:blog-4775830397192165042.post-26795055606774400122014-02-24T01:41:27.252-08:002014-02-24T01:41:27.252-08:00String a ="ja";
String b="va";...String a ="ja";<br />String b="va";<br />String c="do";<br />String d="main";<br /><br />System.out.println(a.concat(b).concat(c).concat(d));<br /><br />In this example concat called again and again , so how many objects it will create?<br />my question is a.concat(b) is one object , then concat(c) 2nd object then concat(d) will create 3rd object in stringpool. My doubt created because concat method returns string,so is it creating new new object each time it called. (I know if there is no object reference present , then it will be garbage collected) sunilhttps://www.blogger.com/profile/12960484075721803663noreply@blogger.comtag:blogger.com,1999:blog-4775830397192165042.post-75663345249800894352013-09-16T07:57:31.061-07:002013-09-16T07:57:31.061-07:00Hey I just checked it out and this:
String first ...Hey I just checked it out and this:<br /><br />String first = "first string" ;<br />String second = "second string";<br />String fourth = first.concat(second+"nothing");<br /><br />WORKS!<br /><br />This means that concat can indeed take more than one value as shown in line 3.<br />This is the output that Eclipse returns:<br /><br />first stringsecond stringnothingAbhishek Jainhttps://www.blogger.com/profile/01802342254327013707noreply@blogger.comtag:blogger.com,1999:blog-4775830397192165042.post-23094001326271382812013-08-15T04:29:01.956-07:002013-08-15T04:29:01.956-07:00Your point is correct in its own sense and obvious...Your point is correct in its own sense and obviously we can concat more than one string using 'concat()' <i>repeatedly</i> as shown in your example. But my point is saying that concat() method takes only one argument like a.concat(b), not more than one as concat(a,b) while this is not the case with '+' operator. :)Rajinderhttps://www.blogger.com/profile/07874702857035374398noreply@blogger.comtag:blogger.com,1999:blog-4775830397192165042.post-31127068474596584762013-05-29T06:47:42.437-07:002013-05-29T06:47:42.437-07:00String a ="ja";
String b="va"...String a ="ja";<br /> String b="va";<br /> String c="do";<br /> String d="main";<br /><br />System.out.println(a.concat(b).concat(c).concat(d));<br /><br />So we can concat any number of strings, kindly change your second point. Thanks.Anonymousnoreply@blogger.com