gpt4 book ai didi

java - 遍历数组列表 - java

转载 作者:行者123 更新时间:2023-12-01 13:12:21 25 4
gpt4 key购买 nike

public void display(detailTom tomData)
{
ArrayList<detailTom> temp = new ArrayList<detailTom>();

for (int i=0;i<tomData.toString().length();i++)
{
temp=tomData[i];
System.out.println(temp.getMark1());
}


}

大家好,

我正在尝试迭代数组列表 tomData,它是一个对象数组列表。我正在尝试迭代列表并显示对象“Mark1”的变量。

错误是“需要数组,但找到了detailTom”

有什么想法吗?或者通过 tomData 进行迭代的任何其他方式?

最佳答案

您提供的内容并没有真正意义,但根据评论,我猜测您正在寻找的答案如下所示:

public void display(List<DetailTom> tomData) {
for (DetailTom detail : tomData) {
System.out.println(detail.getMk1());
}
}

我已将您的类从 detailTom 重命名为 DetailTom,就像 convention in Java 一样。 :

Names of class types should be descriptive nouns or noun phrases, not overly long, in mixed case with the first letter of each word capitalized.

关于java - 遍历数组列表 - java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22749336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com