Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue with ArrayList<ArrayList<String>>
    primarykey
    data
    text
    <p>This code was EDITED according to advice from trutheality.</p> <p>I am having trouble coming up with a good title for this one - if you have a better idea please feel free to change it.</p> <p>I am creating a two dimensional ArrayList. For that I fill up an <code>ArrayList&lt;String&gt;</code> and then add it to <code>ArrayList&lt;ArrayList&lt;String&gt;&gt;</code>. I do that inside a loop and I was hoping to get a fresh <code>ArrayList&lt;String&gt;</code> every time. This doesn't happen so <code>ArrayList&lt;ArrayList&lt;String&gt;&gt;</code> gets filled up with <strong>accumulations</strong> of <code>ArrayList&lt;String&gt;</code> because each time I fill up <code>ArrayList&lt;String&gt;</code> it just adds the what it already has.</p> <pre><code>ArrayList&lt;String&gt; oneD = new ArrayList&lt;String&gt;(); ArrayList&lt;ArrayList&lt;String&gt;&gt; twoD= new ArrayList&lt;ArrayList&lt;String&gt;&gt;(); Cursor tSCursor = retrieveTS(tId); tSCursor.moveToFirst(); for (int i = 0; i &lt; tSCursor.getCount(); i++) { stockId = tSCursor.getString(tSCursor.getColumnIndex("_id")); oneD.add(sId); oneD.addAll(retrieveSFinParams(sId)); twoD.add(sFinParams); tSCursor.moveToNext(); } </code></pre> <p>I tried sFinParams.clear() but as Java users references in the containers, when I use clear() I also loose the values in the 2D ArrayList.</p> <p>How can I get a fresh ArrayList each time so when I full up the 2D ArrayList I don't duplicate the contents of the 1D ArrayList?</p> <p>I appreciate any help, D</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload