-2

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.

1

3 Answers 3

1
StringBuilder sb=new StringBuilder();
for (Long l:list)
    sb.append(l);
Sign up to request clarification or add additional context in comments.

Comments

0

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;
}

Comments

0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.