I have a list of objects and I want to populate one attribute for each object in list. I can do it using for loop like this.
for(Car car : cars) {
String abcd = getSomeValue();
car.setAbcd(abcd);
}
Can I do the same thing using Lambda in Java8.
Yes, you can use forEach
:
cars.forEach(c -> c.setAbcd(getSomeValue()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With