title: Adding ArrayList to TreeMap within a while cycle
body: <p>I'm retrieving data from a table in a database and add the whole row to a <code>TreeMap</code>.</p>
  
  <p>I'm using the following code:</p>
  
  <pre><code>ArrayList&lt;String&gt; listaValores = new ArrayList();
  TreeMap&lt;Integer, ArrayList&gt; tmValores = new TreeMap&lt;&gt;();
  </code></pre>
  
  <p>(...)</p>
  
  <pre><code>    while (rs.next()) 
      {
          listaValores.clear();
          for(int i=2; i&lt;=ncolunas; i++)
          {
              listaValores.add(rs.getString(i));
          }
          tmValores.put(rs.getInt(1), listaValores);   
      }
  </code></pre>
  
  <p>My <code>TreeMap</code> keys are inserted fine but the values are always repeated as the values from the last line as a result from the SELECT * FROM Table query.</p>
  
  <p>So if my table is:</p>
  
  <pre><code>id | name | last name | 
  1  | joe  | lewis     | 
  2  | mark | spencer   | 
  3  | mike | carter    | 
  4  | duke | melvin    |
  </code></pre>
  
  <p>My <code>TreeMap</code> contains:</p>
  
  <pre><code>1=&gt; duke, melvin  
  2=&gt; duke, melvin  
  3=&gt; duke, melvin  
  4=&gt; duke, melvin
  </code></pre>
  
  <p>Instead of (as I wanted)</p>
  
  <pre><code>1=&gt; joe, lewis 
  2=&gt; mark, spencer 
  3=&gt; mike, carter 
  4=&gt; duke melvin
  </code></pre>
  
  <p>Can anyone point me out where is the problem?</p>