Possible Duplicate:
Best way to convert an ArrayList to a string
I need your help! I have array of JSon (esponse from Facebook). ArrayList. How can convert this array to String? Thanks.
Possible Duplicate:
Best way to convert an ArrayList to a string
I need your help! I have array of JSon (esponse from Facebook). ArrayList. How can convert this array to String? Thanks.
best way would be to iterate over ArrayList
and build a String
ArrayList<Long> list = new ArrayList<Long>();
String listString = "";
for (long l : list)
{
listString += String.valueOf(l) + "\n";
}
UPDATE
using StringBuilder
is much better approach as Strings are immutable and everytime you append to String
it creates new String
in memory.
also
"+" operator is overloaded for String
and used to concatenated two String
. Internally "+" operation is implemented using either StringBuffer
or StringBuilder
.
Try using StringBuilder class
public String ConvertArrayToString(Long[] longArray)
{
if(longArray != null)
{
StringBuilder sb = new StringBuilder(longArray.length);
for(int i = 0; i < longArray.length; i++)
{
sb.append(longArray[i]);
}
return sb.toString();
}
return null;
}