title: Java LinkedHashMap: what's the difference in these two?
body: <p>EDIT: The entire code and database creation script can be found from <a href="http://gitorious.org/scheator" rel="nofollow noreferrer">http://gitorious.org/scheator</a> . The database script is in Schema/.</p>
  
  <p>I have the following Java code:</p>
  
  <p>A LinkedHashMap defined in an abstract class as </p>
  
  <pre><code>LinkedHashMap&lt;Object, Data&gt; list;
  </code></pre>
  
  <p>A descendant class that initializes this list like this:</p>
  
  <pre><code>list = new LinkedHashMap&lt;Integer, Data&gt;();
  </code></pre>
  
  <p>I add items like this:</p>
  
  <pre><code>    String id = rs.getString(FIELDS[0]);
      String name = rs.getString(FIELDS[1]);
      Data team = new Data(Integer.parseInt(id.trim()), name);
      list.put(id, team);
  </code></pre>
  
  <p>Now when I do this:</p>
  
  <pre><code>    System.err.println("delete() count: " + list.size());
  
      System.err.println("delete() key value " + key);
      Data obj;
      obj = (Data)list.remove(key);
      deletedList.put(key, obj);
      System.err.println("delete() count: " + list.size());
  </code></pre>
  
  <p>Nothing is removed from the list, i.e. the first and last prints print the same size(). The key is also correct (I have verified there is an item by that id).</p>
  
  <p>However, and this is my question, if I add the values like this:</p>
  
  <pre><code>    Integer id = rs.getInt(FIELDS[0]);
      String name = rs.getString(FIELDS[1]);
      Data team = new Data(id, name);
      list.put(id, team);
  </code></pre>
  
  <p>The code works! Shouldn't parseInt() produce a similar key to getInt()? Why does the second version work but the first doesn't? I spent a good hour debugging this until I found the reason and I still can't figure out the reason.</p>