title: Calculate next work day based on custom holiday calendar using java
body: <p>Im trying to calculate Next Working day by adding specific number of days based on custom holiday calendar from database.</p>
  
  <p>Eg:<br>
  - Current Day:9th March<br>
  - Holidays: 10th March, 12th March , 13th March<br>
  - Days to add: 5  </p>
  
  <p>The result should fetch me: 17th Match</p>
  
  <p>Is there a easy way to handle this in java?</p>
  
  <p>I have the followingcode written   </p>
  
  <pre><code>public class TestNextWorkinDay {
  
      public static void main(String[] args) throws ParseException {
          // TODO Auto-generated method stub
          TestNextWorkinDay d = new TestNextWorkinDay();
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
          Date fDate = sdf.parse("2019-04-09");
  
          //adding holidays to List
          String date1="2019-04-10";
          String date2="2019-04-12";
          String date3="2019-04-13";
  
          ArrayList&lt;String&gt; dates = new ArrayList&lt;&gt;();
          dates.add(date1);
          dates.add(date2); 
          dates.add(date3);
          String dueDate = d.getNextWorkingDay(fDate ,5, dates);
          System.out.println("due Date " + dueDate);
      }
  
  
      public String getNextWorkingDay(Date fDate,int bday , ArrayList&lt;String&gt; dates){
          Calendar cal = Calendar.getInstance();
          cal.setTime(fDate);
          SimpleDateFormat fdate = new SimpleDateFormat("yyyy-MM-dd");
          while(bday &gt; 0){
              cal.add(Calendar.DAY_OF_MONTH, 1);
             String date= fdate.format(cal.getTime());
              if(checkIfNonWorkingDay(date , dates)){
                  bday--;
              }
          }
          return fdate.format(cal.getTime());
      }
  
      public boolean checkIfNonWorkingDay(String cal , ArrayList&lt;String&gt; dates){
  
          if(dates.contains(cal)){
              return false;
          }
          return true;
      }
  
  
  
  
  
  }
  </code></pre>