title: servlet ArrayList and HashMap
body: <pre><code>List&lt;Map&lt;String, Object&gt;&gt; data = new ArrayList&lt;Map&lt;String, Object&gt;&gt;();
  Map&lt;String, Object&gt; item = new HashMap&lt;String, Object&gt;();
  
  data.clear();
  item.clear();
  int i = 0;
  while (i &lt; 5){
     item.put("id", i);
     i++;
     out.println("id: " + item.get("id"));
     out.println("--------------------------");
     data.add(item);
  }
  for(i=0 ; i&lt;5 ; i++){
     out.println("print data[" + i + "]" + data.get(i));
  }
  </code></pre>
  
  <p>Result of that is:</p>
  
  <blockquote>
  id: 0<br>
  --------------------------<br>
  id: 1<br>
  --------------------------<br>
  id: 2<br>
  --------------------------<br>
  id: 3<br>
  --------------------------<br>
  id: 4<br>
  --------------------------<br>
  print data[0]{id=4}<br>
  print data[1]{id=4}<br>
  print data[2]{id=4}<br>
  print data[3]{id=4}<br>
  print data[4]{id=4}<br>
  </blockquote>
  
  <p>Why only last element is stored?</p>