java add function,all become one last set of data when added
<p>there are only 3 sets of data in turn1.length,when temp added,there should have three different sets of data.But,after i add,even there is 3 group objects,the date in it upexpectedly is the last group of date,all.
I see three different data in debug mode,current attribute will cover the prev data in temp each cycle.</p>

<p>how can i fix it?</p>

<pre><code>  String[] turn1 = idList.split(","); 
  String[] turn2 = labelList.split(","); 
  Attribute attribute = new Attribute(); 
  List&lt;Attribute&gt; Temp = new ArrayList&lt;Attribute&gt;(); 

for(int i=0;i&lt;turn1.length;i++){ 
    long getId; 
    getId = Integer.parseInt(turn1[i]); 
    attribute.setId(getId); 
    attribute.setLabel(turn2[i]); 
    Temp.add(attribute); 
   } 
for(int i=0;i&lt;3;i++) 
System.out.println(Temp.get(i)); 
</code></pre>
