-2

I'm creating a program which can take appointments. E.g. A doctors appointment, it will take name, number and date the appointment was created into an array.

if i want to check between date a and date b and see what appointments are between those dates how would i go about this?

I'm using the Gregorian Calendar

  • 3
    Just to be clear. You are not using Java 8? And showing some code wouldn't hurt at all ... a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) would be great – Robin Topper May 10 '17 at 19:58
  • Both `Calendar` and `Date` have methods `after` and `before`. – Lew Bloch May 10 '17 at 20:01
  • 1
    Please, search Stack Overflow before posting. Tip: All the basic date-time questions have already been asked and answered. – Basil Bourque May 10 '17 at 23:52
  • “I'm using the `GregorianCalendar`”. Consider not doing that. The modern classes in the `java.time` package are much nicer to work with. – Ole V.V. May 11 '17 at 04:56

1 Answers1

0

Since you already have the appointment dates in an array, you could use Arrays.binarySearch(appoinments, a) to find the first appointment on or after a, and similarly Arrays.binarySearch(appoinments, b) for the last appointment on or before b.

jingx
  • 3,698
  • 3
  • 24
  • 40