这是我要实现的目标:

    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);
            }

最佳答案

使用索引为for的“正常” i

// 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/

10-12 18:52