你能解释一下这个for-loop
吗?
beanNote bnote = new beanNote();
String somme=0;
for (Note note : bnote.getNotes()) {
somme = somme + note.getNoteMat();
}
我只知道经典的for-loop
:
for(int i=0; i<1000; i++){
// do job .....
}
答案 0 :(得分:4)
相当于:
for(Note note = bnote.getFirstNote(); bnote.stillNotes(); note = bnote.getTheFolowingNote()){
somme = somme + note.getNoteMat();
}
答案 1 :(得分:3)
for (Note note : bnote.getNotes()) {
somme = somme + note.getNoteMat();
}
它的e nhanced for-loop
,有时甚至被称为java版本5中引入的for-each loop
,它使得集合和数组的迭代变得灵活。
答案 2 :(得分:2)
这是for-each构造:bnote.getNotes()返回一个数组或一个Iterable对象,并为该集合中的每个对象执行循环体。