title: I want to make a booking system in java, and I cannot check the dates given between another dates
body: <p>I want to make a booking system for rooms. The user will insert a date from startDate to endDate. Alright, after thats lets say that another user will want to book the same room in between the same dates as the user.So, if the first user booked the room from 2017-1-1(yyyy-MM-dd) to 2017-1-8, the next user cannot book the same room in exactly these dates or from 2017-1-3 to 2017-1-10.the user will be informed that he/she can book only before 1/1 or after 1/8.</p>
  
  <p>Here is my code:        </p>
  
  <pre><code>import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.*;
  
  public class Main {
      public static void main(String[] args) {
  
  
          String startDateFirst = "2016-1-1";
          String endDateFirst = "2016-1-4";
  
          Date convertedStartDateFirst = convertDate(startDateFirst);
          Date convertedEndDateFirst = convertDate(endDateFirst);
  
          List&lt;Date&gt; myList = new ArrayList&lt;Date&gt;(getDaysBetweenDates(convertedStartDateFirst,convertedEndDateFirst));
  
  
          String startDate2 = "2016-1-1";
          String endDate2 = "2016-1-3";
  
          Date convDateStr2 = convertDate(startDate2);
          Date convDateEnd2 = convertDate(endDate2);
  
          List&lt;Date&gt; myListSecond = new ArrayList&lt;Date&gt;(getDaysBetweenDates(convDateStr2,convDateEnd2));
  
          System.out.println("FIRST BOOKING: " + getDaysBetweenDates(convertedStartDateFirst,convertedEndDateFirst));
          System.out.println("SECOND BOOKING: " + getDaysBetweenDates(convDateStr2,convDateEnd2));
  
  
         for (int i=0; i&lt;=myListSecond.size(); i++)
          {
  
                  if ((myList.get(i).getTime() &gt;= myListSecond.get(i).getTime() &amp;&amp; myList.get(i).getTime() &lt;= myListSecond.get(i).getTime())) {
                      System.out.println(myListSecond.get(i) + " is taken");
                  } else if (myList.get(i).equals(myListSecond.get(i))) {
                      System.out.println(myListSecond.get(i) + " equal");
                  } else {
                      System.out.println(myListSecond.get(i) + "is not");
                  }
  
  
          }
  
  
  
      }
  
      public static Date convertDate(String strDate)
      {
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
          try{
              Date date = format.parse(strDate);
              //String finalDate = format.format(date);
              return date;
          }catch (ParseException e)
          {
  
          }
          return null;
      }
      public static List&lt;Date&gt; getDaysBetweenDates(Date startdate, Date enddate)
      {
          List&lt;Date&gt; dates = new ArrayList&lt;Date&gt;();
          Calendar calendar = new GregorianCalendar();
          calendar.setTime(startdate);
  
          while (calendar.getTime().before(enddate))`enter code here`
          {
              Date result = calendar.getTime();
              dates.add(result);
              calendar.add(Calendar.DATE,1);
          }
          return dates;
      }
  
  }
  </code></pre>
  
  <p>Although, in <code>getDaysBetweenDates</code> I get the date but with -1 date, why? and how do I return the exactly dates.</p>