如何在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()));
try this
list.forEach(element->{
TransportAttendanceFormBean tb = new TransportAttendanceFormBean();
tb.setDate(element.getAttendancedate().toString());
});
或者(不需要在每次迭代中创建新对象)
TransportAttendanceFormBean tb = new TransportAttendanceFormBean();
list.forEach(element->{
tb.setDate(element.getAttendancedate().toString());
});