title: Java: linked list of items problem
body: <p>I have used linked lists before with Strings, doubles, etc., and they always worked exactly as expected.  But now I am forming a linked list of items, and whenever I add a new element to the list, all objects in the list apparently become equal to the last object.</p>
  
  <p>The essential code is as below:</p>
  
  <pre><code>import java.util.*;
  
  public class Global
  {
  
    static public LinkedList&lt;StockInfo&gt; DiaryStocks = new LinkedList&lt;StockInfo&gt;();
  
    static public class StockInfo    //info related to each stock in diary
    {
      String recordDate;             
      String ticker;
      int   status;                  
      String buyDate;
      String sellDate;
      double buyPrice;
      double sellPrice;
      double nmbrShares;
    }//StockInfo
  
  //The following function places the Diary data for a stock in the arraylist
  
   static public void AddDiaryData(StockInfo thisdata)
    {
      String tckr;
      int i;
  
      DiaryStocks.add(thisdata);
  
      for (i = 0; i &lt; DiaryStocks.size(); i++)   //this is debug code
      {
        tckr = DiaryStocks.get(i).ticker;
      }
    } 
  }
  </code></pre>
  
  <p>As I said, when single stepping through the debug code near the bottom, each time I add a new item to the list, the list size grows as it should, but the tckr item only corresponds to the last item added.</p>
  
  <p>Any insights into this puzzle would be greatly appreciated.</p>
  
  <p>John Doner</p>