當前位置:編程學習大全網 - 網站源碼 - 請Java高手幫我解釋壹下這段代碼,謝謝了

請Java高手幫我解釋壹下這段代碼,謝謝了

for(Student st : students)

System.out.println(st.toString());

這相當於壹個foreach語句~是jdk1.5以上的版本才有的

相當於

for(int i=0;i<students.size();i++){

Student st = (Student)students.get(i);

System.out.println(st.toString());

}

或者用叠代其也可以實現:

Iterator it = students.iterator();

while(it.hasNext()){

Student st = (Student)it.next();

System.out.println(st);

}

  • 上一篇:整型的最小取值為什麽是-32768,而不是-32767
  • 下一篇:matlab 曲面擬合 求參數
  • copyright 2024編程學習大全網