Assuming that class CatchesItem
has time
field defined as LocalDateTime
, the check for today’s timestamp may be implemented as follows:
import java.time.*;
// ...
LocalDate today = LocalDate.now();
for (CatchesItem item : items) {
if (today.equals(item.getTime().toLocalDate())) {
item.setAmount(item.getAmount() + 5); // add some value to amount
}
}
items.forEach(System.out::println);
Output (for the input data as of Feb 18)
CatchesItem(amount=1, condition=0.0, time=2021-02-17T17:10:42)
CatchesItem(amount=4, condition=1.0, time=2021-02-17T17:10:48)
CatchesItem(amount=10, condition=2.0, time=2021-02-18T17:10:54)
1
solved How to iterate over Array List and modify elements inside the object in Java?