I want the Java code for converting an array of strings into an string.
You could do this, given an array
| |||||||||
feedback
|
Try the Arrays.toString overloaded methods. Or else, try this below generic implementation:
| |||||||
feedback
|
Use Apache commons
Produces:
| |||||
feedback
|
You want code which produce string from arrayList,
you can do this in 2 ways: using String as result or StringBuffer/StringBuilder. Example:
...but this isn't good practice because of performance reason. Better is using StringBuffer (threads safe) or StringBuilder which are more appropriate to adding Strings | |||
feedback
|
I like using Google's Guava Joiner for this, e.g.:
would produce the same String as:
| |||||||||||
feedback
|
Either use
You can modify the above depending on what characters, if any, you want in between strings. You may also see near identical code to the above but using DON'T use a string and just append to it with += like some of the answers show here. This sends the GC through the roof because you're creating and throwing away as many string objects as you have items in your array. For small arrays you might not really notice the difference, but for large ones it's orders of magnitude slower. | ||||
feedback
|
array.toString()
? Be more specific. – Stas Kurilin Mar 12 '11 at 15:36