如何在jdk8中使用这样的for循环。
for (ClassAttendanceParent classAttendanceParent : list) {
TransportAttendanceFormBean tb = new TransportAttendanceFormBean();
tb.setDate(classAttendanceParent.getAttendancedate().toString());
}
JDK8中的(如何转换上面的for循环)
list.forEach((ClassAttendanceParent element) -> System.out.println(element.getAttendancedate()));
答案 0 :(得分:0)
试试这个
list.forEach(element->{
TransportAttendanceFormBean tb = new TransportAttendanceFormBean();
tb.setDate(element.getAttendancedate().toString());
});
或(不需要在每次迭代中创建新对象)
TransportAttendanceFormBean tb = new TransportAttendanceFormBean();
list.forEach(element->{
tb.setDate(element.getAttendancedate().toString());
});