This is my actual for-each loop.I need to convert that into java8 for loop.
for (PromotionEntity promotionEntity : pestudents) {
List<ClassAttendanceChild> attendancelist = session.createQuery("from ClassAttendanceChild where attendanceadded='" + day + "' and pid.pId='" + promotionEntity.getpId() + "'").list();
if (!attendancelist.isEmpty()) {
ClassAttendanceChild attendenceDetails = (ClassAttendanceChild) attendancelist.get(0);
if (attendenceDetails.getStatus().equalsIgnoreCase("yes")) {
present++;
System.out.println("present = " + present);
} else {
Absent++;
System.out.println("Absent = " + Absent);
}
} else {
nottaken++;
System.out.println("nottaken = " + nottaken);
}
}
How to convert that to java8 for loop,I am getting exceptions in that variable increment:
pestudents.forEach(promotionEntity -> {
List<ClassAttendanceChild> attendancelist = session.createQuery("from ClassAttendanceChild where attendanceadded='" + day + "' and pid.pId='" + promotionEntity.getpId() + "'").list();
if (!attendancelist.isEmpty()) {
ClassAttendanceChild attendenceDetails = (ClassAttendanceChild) attendancelist.get(0);
if (attendenceDetails.getStatus().equalsIgnoreCase("yes")) {
// present++;
// System.out.println("present = " + present);
} else {
// Absent++;
// System.out.println("Absent = " + Absent);
}
} else {
// nottaken++;
// System.out.println("nottaken = " + nottaken);
}
});
.parallelStream()and make it thread safe.