gpt4 book ai didi

java - 如何同时迭代这些列表?

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

这就是我想要实现的目标:

    public ArrayList<Point> startPoints = new ArrayList<Point>();
public ArrayList<Point> endPoints = new ArrayList<Point>();

for (Point startPoint : startPoints) { // <-- How do I do I do 2 at the same time?
g.fillOval(startPoint .x, startPoint.y, 10, 10);
g.drawLine(startPoint .x, startPoint.y, endPoint.x, endPoint.y);
}

最佳答案

使用带有索引i的“普通”for

// if list1 and list2 have the same length
for(int i = 0;i<list1.size();i++){
list1.get(i); // do something with that
list2.get(i); // do something else with that
}

关于java - 如何同时迭代这些列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19745467/

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