java初学者遇到的问题for (Employee e : employees),请求大家帮助。
private static void writeData(Employee[] employees, PrintWriter out) throws
IOException {
// write number of employees
out.println(employees.length);
for (Employee e : employees)
e.writeData(out);
}
for (Employee e : employees)这句是什么意思呀?for循环不是至少要有for(;;)的吗?这句我实在看不懂。请求大家帮助。
------解决方案--------------------1。5 新增的foreach 循环,只要实现 Iterable 接口或是数组
------解决方案--------------------它是将employees里的元素取出来
------解决方案--------------------
嗯,就是JDK提供方便你输出数组和Iterator的写法
相当于:
for (int i = 0; i <employees.length; i++)
{
Employee e = employees[i];
e.writeData(out);
}