Possible Duplicate:
A method to reverse effect of java String.split()?
How do I take all the values within String[] args and make it into a single String variable?
Possible Duplicate:
A method to reverse effect of java String.split()?
How do I take all the values within String[] args and make it into a single String variable?
Note: it's more efficient to use a StringBuilder object, but this is a simpler example:
public String concat(String[] args) {
String result = ""
for (String arg : args) {
result += arg;
}
return result;
}
I prefer Apache Commons StringUtils
. StringUtils.join(Object[] array, String separator)
will join all the objects in the array with the given separator.
If you want a subarray of your current array (e.g. skip the first three elements), use this:
StringUtils.join(ArrayUtils.subarray(myArray, 3, myArray.length), ",");
You can override toString()
method and within this method, you can implement by doing loop through the String array and return the concatenated string in the format that you want.