对于环应该打印出来的ArrayList属性和其它的ArrayList属性 [英] For-loop which should print out ArrayList attribute and other ArrayList Attribute

查看:142
本文介绍了对于环应该打印出来的ArrayList属性和其它的ArrayList属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从两个不同的ArrayList在同一syso打印出属性。不能让它工作,自杀了找出为什么它不

I am trying to print out attribute from two different ArrayLists in the same syso. Cant get it to work and killed myself finding out why it doesnt

    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对于每个结果,但不能让它名为藏汉工作。所以我的问题是:什么我做错了。

Works fine just printing out the resultValue for each Result but cant get it to work with the name aswell. So my question is: What am I doing wrong?

推荐答案

我想你应该更改

for (int x = 0; x < resultlist.size(); x++) {
    Athlete del = athletes.get(i);
    ...

for (int x = 0; x < athletes.size(); x++) {
    Athlete del = athletes.get(x);
    ...

,以便通过运动员 ArrayList的正常循环,因为2的ArrayList可能是不一样的尺寸。此外,这样你会扫描每个结果所有的运动员

so as to loop through the athletes arraylist correctly, since the 2 arraylists are probably not the same size. Also, this way you would scan all the athletes for each Result.

这篇关于对于环应该打印出来的ArrayList属性和其它的ArrayList属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆