My data set is a payment schedule consisting of due dates and amounts. I'm storing this in a TreeMap
.
Map<LocalDate, BigDecimal> paymentSchedule = new TreeMap<>();
paymentSchedule.put(LocalDate.parse("2017-01-01", formatter), new BigDecimal("1000"));
paymentSchedule.put(LocalDate.parse("2017-02-01", formatter), new BigDecimal("1000"));
paymentSchedule.put(LocalDate.parse("2017-03-01", formatter), new BigDecimal("1000"));
paymentSchedule.put(LocalDate.parse("2017-04-01", formatter), new BigDecimal("1000"));
paymentSchedule.put(LocalDate.parse("2017-05-01", formatter), new BigDecimal("1000"));
paymentSchedule.put(LocalDate.parse("2017-06-01", formatter), new BigDecimal("1000"));
for (Map.Entry<LocalDate, BigDecimal> paymentPeriod : paymentSchedule.entrySet()) {
LocalDate dueDate = paymentPeriod.getKey();
BigDecimal amountDue = paymentPeriod.getValue();
}
How can I "peek ahead" during an iteration without advancing the iteration?
For example, when I'm working with the Map.Entry for {2017-03-01,1000}
, I want to look up the next due date for a calculation.