(x:y){...}的工作原理是什么?

时间:2015-05-15 11:34:45

标签: java for-loop

I have seen this kind of for-loop around但我不太明白。有人可以解释它是如何工作的吗?

链接示例:

public static void printPersonsWithinAgeRange(
    List<Person> roster, int low, int high) {
    for (Person p : roster) {
        if (low <= p.getAge() && p.getAge() < high) {
            p.printPerson();
        }
    }
}

编辑:问题已在此处回答:How does the Java 'for each' loop work?

编辑2: Oracle教程:https://docs.oracle.com/javase/tutorial/java/nutsandbolts/for.html

0 个答案:

没有答案