I have a arrayList as follows:
[{hours: 48, cancellationCharges: 0},
{hours: 12, cancellationCharges: 10},
{hours: 0, cancellationCharges: 20}]
The above array means that from 0 to 12 hours before departure, a cancellation charge of 20% is applicable. From 12 hours to 48 hours before departure, a cancellation charge of 10% is applicable and beyond 48 hours, there is not cancellation charge at all.
I want to filter the above to find out the cancellation charges which are applicable beyond a day. i.e., in the above case, the result should be
[{hours: 48, cancellationCharges: 0},
{hours: 12, cancellationCharges: 10}]
I tried to filter by condition hours >= 24 and if the last element does not have hours as 24, I iterated again to find the first element with hours < 24. Is there a better way to solve this. I am using java12.