मैं अपने "लूप" को "लूप" के लिए कैसे बदलूं? [डुप्लिकेट]
Nov 28 2020
मैं इसे प्रत्येक लूप के लिए लूप में बदलने की कोशिश कर रहा हूं।
for (int i = 0; i < appointments.size(); i++) {
if (appointments.get(i).equals(appointment)) {
appointments.get(i).setAvailability(true);
}
}
जवाब
ElliottFrisch Nov 28 2020 at 18:46
for-each
appt
में है appointments
। पसंद,
for (Appointment appt : appointments) {
if (appt.equals(appointment)) {
appt.setAvailability(true);
}
}
या, यदि जावा 8+ का उपयोग कर रहे हैं तो आप कर सकते stream
हैं appointments
। पसंद,
appointments.stream()
.filter(x -> x.equals(appointment))
.forEach(appt -> appt.setAvailability(true));