title: how to add a map to arraylist, by value
body: <p>I am trying to add an object of class Document to an arraylist in a loop.
  the problem is that every time the object changes, the prevous contents of the list changes too</p>
  
  <p>here's my Document class:</p>
  
  <pre><code>public class Document {
      public Map&lt;String, Double&gt; tokens;
      public String category;    
  }
  </code></pre>
  
  <p>and I have the list dataset:</p>
  
  <pre><code>List&lt;Document&gt; dataset = new ArrayList&lt;Document&gt;();
  </code></pre>
  
  <p>I read all the tokens of a document from a file to a map named counts. then do as follows</p>
  
  <pre><code>doc = new Document();
  doc.tokens = counts;
  doc.category=sampleCategory;
  dataset.add(doc);
  
  counts.clear();
  </code></pre>
  
  <p>but every time i read a new doc, the contents of dataset changes to the values of new doc.
  So how can I add the doc by value, not by reference?</p>