请问Map用for循环添加后为什么只添加了最后一个对象
package game;
public class Paizus {
public int ID;
public String name;
public Paizus(int ID, String name) {
this.ID=ID;
this.name=name;
}
}
package game;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class Sumgames{
Map<String,Paizus>newmap=new HashMap<String,Paizus>();
public void pukepai() {
Paizus[] pai= {new Paizus(0,"方片2"),new Paizus(1,"梅花2"),new Paizus(2, "黑桃2"),new Paizus(3, "红桃2"),
new Paizus(4,"方片3"),new Paizus(5,"梅花3"),new Paizus(6, "黑桃3"),new Paizus(7, "红桃3")};
for( int i1=0;i1<8;i1++) {
newmap.put("i1",pai[i1]);
}
System.out.println("总长为:"+newmap.size());
System.out.println("开始洗牌,洗牌后为:");
Set<String> keySet = newmap.keySet();
for (String string : keySet) {
Paizus paizu1=newmap.get(string);
System.out.println(paizu1.name);
}
}
public static void main(String[] args) {
Sumgames test=new Sumgames();
test.pukepai();
}
}