[英]How use streams for loop in jdk8?
在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()));
試試這個
list.forEach(element->{
TransportAttendanceFormBean tb = new TransportAttendanceFormBean();
tb.setDate(element.getAttendancedate().toString());
});
或者(無需在每次迭代中創建新的 object)
TransportAttendanceFormBean tb = new TransportAttendanceFormBean();
list.forEach(element->{
tb.setDate(element.getAttendancedate().toString());
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.