tag:blogger.com,1999:blog-8712770457197348465.post8778141816877126774..comments2024-03-29T00:43:22.798-07:00Comments on Javarevisited: 3 Examples to Concatenate String in Javajavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-8712770457197348465.post-24656756515891877552021-11-30T12:47:41.895-08:002021-11-30T12:47:41.895-08:00how can you validate the name if it contains both ...how can you validate the name if it contains both firstName and lastName<br />devhttps://www.blogger.com/profile/14932696073871016074noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-6719533093938934852020-04-15T02:26:59.888-07:002020-04-15T02:26:59.888-07:00read three input string, concatenate and print usi...read three input string, concatenate and print using JSP and servlet with Jsp script tag and expression tagAnonymoushttps://www.blogger.com/profile/02902542272056094467noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-24846998301570647172017-06-05T10:26:29.197-07:002017-06-05T10:26:29.197-07:00I have recently came across a problem in load test...I have recently came across a problem in load testing. String is concatenated using + operator.Concatenated String corrupts only while using VM parameters -XX:+UseCompressedStrings -XX:+OptimizeStringConcat. Can somebody throw some light on it.. I will share my results if I find before someone explains it..noanhttps://www.blogger.com/profile/16778600748906236887noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-83702256003943085572016-08-14T02:32:39.308-07:002016-08-14T02:32:39.308-07:00good job
good job<br />Anonymoushttps://www.blogger.com/profile/08386118523996691702noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-14490350139280388662016-06-25T21:23:17.492-07:002016-06-25T21:23:17.492-07:00@Jane, glad that you like this tutorial about diff...@Jane, glad that you like this tutorial about different ways of concatenating Strings. If you like, don't forget to share, it makes difference. Thanksjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-72446855105779370252016-06-25T21:00:00.462-07:002016-06-25T21:00:00.462-07:00ThanksThanksJane Rosehttps://www.blogger.com/profile/06385351917308255873noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-64596152490048271692016-04-13T11:07:38.016-07:002016-04-13T11:07:38.016-07:00Given two strings first and second, appends onto f...Given two strings first and second, appends onto first all characters in second that<br />don't already occur in first <br /><br />Helpyayhttps://www.blogger.com/profile/01693389499108811689noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-80780202831580552642016-02-04T11:53:33.734-08:002016-02-04T11:53:33.734-08:00Nice article.. Thanks it helpedNice article.. Thanks it helpedNataraj Boyanoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-57059834505510187142015-01-10T21:09:09.178-08:002015-01-10T21:09:09.178-08:00@Han.Solo..perfect dude..
If you want to join a Co...@Han.Solo..perfect dude..<br />If you want to join a Collection of Strings you can use the new String.join() method:<br /><br />List list = Arrays.asList("foo", "bar", "baz");<br />String joined = String.join(" and ", list); // "foo and bar and baz"<br />If you have a Collection with another type than String you can use the Stream API with the SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-19440447520191344992015-01-09T21:33:15.842-08:002015-01-09T21:33:15.842-08:00There is also StringJoiner and String.join() which...There is also StringJoiner and String.join() which came with JDK8...Han Solohttps://www.blogger.com/profile/12574196875988408685noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-63439939380808950642015-01-08T19:19:16.075-08:002015-01-08T19:19:16.075-08:00@Javin, the point is, people are often adding stat...@Javin, the point is, people are often adding static strings to avoid long lines. The compiler takes care of it, so don't worry and create a bunch of ugliness in your code.yottzummhttps://www.blogger.com/profile/13512893992219685596noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-54269615605179832882015-01-06T06:08:59.275-08:002015-01-06T06:08:59.275-08:00@Saral, In your test I you are always adding same ...@Saral, In your test I you are always adding same string together. Can you try using loop counter to append and see what it returns? I think StringBuilder should win the race. javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-2183398639636644952015-01-05T23:51:32.050-08:002015-01-05T23:51:32.050-08:00The reason for the slowness when appending many st...The reason for the slowness when appending many strings in a loop using the + operator is that the + operator creates and disposes of a new StringBuffer for every + operator. So not only are you creating many small String objects, but each one of them was created by a temp StringBuffer object. Both the temp String and the temp StringBuffer then get garbage collected.Anonymoushttps://www.blogger.com/profile/10939091044212106220noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-79367563434410447542015-01-05T08:16:43.183-08:002015-01-05T08:16:43.183-08:00Lots of theory - time for some practice!
private ...Lots of theory - time for some practice!<br /><br />private final String s1 = new String("1234567890");<br />private final String s2 = new String("1234567890");<br /><br />Using plain for loops of 10,000,000, on a warmed-up 64-bit Hotspot, 1.6.0_22 on Intel Mac OS.<br /><br />eg<br /><br />@Test public void testConcatenation() {<br /> for (int i = 0; i < COUNT; i++) {<brSARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-89733406211598547262015-01-05T04:25:25.638-08:002015-01-05T04:25:25.638-08:00One could add that StringJoiner (Java 8) and Strin...One could add that StringJoiner (Java 8) and String.format(...)/Formatter are two other ways of "joining" (concatenating) Strings.<br /><br />Christian Ullenboomhttp://www.tutego.denoreply@blogger.com