Forums Register Login

concatenate and join difference

+Pie Number of slices to send: Send
Hello Everyone,
I wrote a small piece of code thinking that join and concatenate works in a similar way. But end up not figuring out why it doesn't work with concatenate. Here is the code.


Output :
Join String: a,b,c,d
name is: a
name is: b
name is: c
name is: d
Concatenate String:

Please guide me through if there is some code changes required.
Regards
Ashwini Sidhanti
1
+Pie Number of slices to send: Send
Welcome to the Ranch

Since a String is immutable, you are losing the results of the concat call; you shou‍ld assign it back to concatString:-
concatString = concatString.concat(name).concat(",");
That will of course produce a different result. I shall leave you to work out how different. It is also inefficient in terms of performance to use concat or similar inside a loop.
+Pie Number of slices to send: Send
Thanks Campbell Ritchie. An important feature of string which I obviously forgot.        Thanks once again  
+Pie Number of slices to send: Send
That's a pleasure
I carry this gun in case a vending machine doesn't give me my fritos. This gun and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 251 times.
Similar Threads
concat 2 strings using constructor
Java file.mkdir() does not work even after chmod set to 777
.concat() with ints
dear all, i created a set of mock exam, please try it.
what's wrong with this code?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 06:57:12.