Add each element of a string on a new line in ArrayList
<p>I have a <code>String</code>, an <code>ArrayList&lt;String&gt;</code> and a <code>Spinner</code>.</p>

<p>In my code, I add <code>String</code> elements in my <code>ArrayList</code> and then in my <code>Spinner</code>. All good, except the fact that everything is on a single line, and I want each of the elements ("one,two,three,four") in a new line.</p>

<p>The main problem is that I do not know what does the <code>String</code> object contains, but I managed to separate the words in the <code>String</code>.</p>

<p>So...How can I break the line after each word in my string and then add it on a new line in my spinner?</p>

<p>Note: I do not know what String <code>accounts</code> contains or how many values it has in it. I receive the string from a post method.</p>

<pre><code>JSONArray userAcounts = objects.getJSONArray("Accounts");

for (int i = 0;i &lt; userAcounts.length();i++){
    JSONObject myStreamingAcounts = userAcounts.getJSONObject(i);
    accountType += myStreamingAcounts.getString("Type");
}
ArrayList&lt;String&gt; spinnerAccounts = new ArrayList&lt;&gt;();

Spinner accounts = (Spinner)findViewById(R.id.accounts);
ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_spinner_item,spinnerAccounts);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
accounts.setAdapter(adapter);
spinnerAccounts.add(System.lineSeparator());
spinnerAccounts.add(accountID.toString());
</code></pre>