Java集合问题 public static void main(String[] args) throws Exception { Map<Integer

Java集合问题

public static void main(String[] args) throws Exception {

Map<Integer,jsonxx> news=new HashMap<Integer,jsonxx>();

// System.out.println(news.get(0));
jsonxx j=new jsonxx();
for(int ass = 0;ass<10;ass++){
String city="呵呵哒"+ass;
j.setA(city);

// System.out.println(j.getA());

String district="呵呵"+ass;
j.setB(district);

// System.out.println(j.getB());

String a2="哈哈"+ass;
j.setC(a2);

// System.out.println(j.getC());

String a3="去你的"+ass;
j.setD(a3);

System.out.println(j.toString());
news.put(ass,j);
}

System.out.println(news.get(0));

为什么一直输出的是9?????
最新回答
钢铁不是铁

2025-03-02 00:00:25

这有啥奇怪的,你就一个j对象,拿出来都是一样的。你把jsonxx j=new jsonxx();放到循环里就不一样了.