I have an object with a currentDate field. It will need to access n next workdays. I have a .csv file with all the workdays.
My current solution:
- Create an
ArrayList<LocalDate> workdaysfrom the .csv. - Get
currentDateIndexfromworkdays.indexOf(currentDate). - Get next
nnext days by iterating overworkdays.get(currentDateIndex + i).
What I don't like about it:
- No way of ensuring that
workdayslist is actually sorted, or doesn't have duplicates. - O(n) complexity of
indexOfmethod.
Is there a collection that will ensure that the workdays are unique and sorted and that can quickly return next n workdays when given the currentDate?