你正在添加 的 相同 强> teststep 要列出的实例 s 每次。
teststep
s
你想要的是每次迭代创建和添加一个新的TestStepMap对象,否则你将始终从循环的早期迭代覆盖该对象的更新。
List<TestStepMap> s = new ArrayList<TestStepMap>(); for (int i=0; i<4; i++) { int index = i; String step = "Step " + (i+1); String data = "Data " + (i+1); String result = "Result " + (i+1); TestStepMap teststep = new TestStepMap(); teststep.setIndex(index); teststep.setStep(step); teststep.setData(data); teststep.setResult(result); s.add(i, teststep); }