我正在尝试从同一系统中的两个不同的 ArrayList 打印属性。无法让它工作并自杀找出为什么它不起作用
for (int i = 0; i < resultlist.size(); i++) {
Athlete matched = null;
Result res = resultlist.get(i);
for (int x = 0; x < resultlist.size(); x++) {
Athlete del = athletes.get(i);
if (res.compStartNumber() == del.startNumber()) {
matched = del;
break;
}
}
System.out.println(matched.surName() + " " + matched.lastName() + " has result: " + res.resultValue());
}
只需打印出每个结果的 resultValue 即可正常工作,但无法使其与名称一起使用。所以我的问题是:我做错了什么?
我认为你应该改变
for (int x = 0; x < resultlist.size(); x++) {
Athlete del = athletes.get(i);
...
to
for (int x = 0; x < athletes.size(); x++) {
Athlete del = athletes.get(x);
...
以便循环遍历athletes
arraylist 正确,因为 2 个 arraylist 可能不一样size
。此外,通过这种方式,您可以扫描每个运动员的所有运动员Result
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)