title: Calendar and array list : how do I assign the date right?
body: <p>below the lastDay variable does not always contain the i+1 of the list. No clue why.
  I am in the course of introducing the Date from Java 8. But still I would like to know what is going wrong...
  Peter (very beginner)</p>
  
  <pre><code>// organize the intervals and split them into the years
          ArrayList&lt;intervall&gt; tmpIntervallList = new ArrayList&lt;intervall&gt;();
          Calendar lastDay = Calendar.getInstance();
  
          for (i = 0; i &lt; deliveryList.size() - 1; i++) {
  
              Log.d(TAG, "my log comments: Intervallanfang " +
                      deliveryList.get(i).getDatumasString() +" nächstes: " + deliveryList.get(i+1).getDatumasString());
              //Beginning of the next intervall -1 is the last day of the Intervall before.
              lastDay.set(deliveryList.get(i+1).getYear(),
                      deliveryList.get(i+1).getMonth(),
                      deliveryList.get(i+1).getDay());
  
              //debugging
              String tmp1String = String.format("%d/%d/%d", lastDay.get(Calendar.DAY_OF_MONTH),
                      lastDay.get(Calendar.MONTH) + 1,
                      lastDay.get(Calendar.YEAR));
              Log.d(TAG, "my log comments: tmp lastday " + tmp1String );
  
              lastDay.add(Calendar.DATE, -1);
  
              //debugging
              String tmpString = String.format("%d/%d/%d", lastDay.get(Calendar.DAY_OF_MONTH),
                      lastDay.get(Calendar.MONTH) + 1,
                      lastDay.get(Calendar.YEAR));
              Log.d(TAG, "my log comments: ende intervall " + tmpString);
  
              intervall tmp2intervall = new intervall(deliveryList.get(i).getAmountFilled(),
                      deliveryList.get(i).getYear(),
                      deliveryList.get(i).getMonth(),
                      deliveryList.get(i).getDay(),
                      lastDay.get(Calendar.YEAR),
                      lastDay.get(Calendar.MONTH),
                      lastDay.get(Calendar.DAY_OF_MONTH));
              tmpIntervallList.add(tmp2intervall);
          }
  </code></pre>
  
  <p>And the outcome is</p>
  
  <p>my log comments: Intervallanfang 01/01/2018 nächstes: 01/02/2018</p>
  
  <p>my log comments: tmp lastday 1/1/2018</p>
  
  <p>my log comments: ende intervall 31/12/2017</p>
  
  <p>my log comments: Intervallanfang 01/02/2018 nächstes: 01/06/2018</p>
  
  <p>my log comments: tmp lastday 1/1/2018</p>
  
  <p>my log comments: ende intervall 31/12/2017</p>
  
  <p>my log comments: Intervallanfang 01/06/2018 nächstes: 01/01/2019</p>
  
  <p>my log comments: tmp lastday 1/1/2019</p>
  
  <p>my log comments: ende intervall 31/12/2018</p>
  
  <p>my log comments: Intervallanfang 01/01/2019 nächstes: 01/01/2020</p>
  
  <p>my log comments: tmp lastday 1/1/2020</p>
  
  <p>my log comments: ende intervall 31/12/2019</p>
  
  <p>my log comments: Intervallanfang 01/01/2020 nächstes: 01/06/2020</p>
  
  <p>my log comments: tmp lastday 1/1/2020</p>
  
  <p>my log comments: ende intervall 31/12/2019</p>
  
  <p>my log comments: Intervallanfang 01/06/2020 nächstes: 02/01/2021</p>
  
  <p>my log comments: tmp lastday 2/1/2021</p>
  
  <p>my log comments: ende intervall 1/1/2021</p>
  
  <p>as requested some more source code</p>
  
  <pre><code>    public  intervall(int amountFilled, int yearBegin, int monthBegin, int 
                 dayBegin, int yearEnd, int monthEnd, int dayEnd) {
                     begin = Calendar.getInstance();
                     end = Calendar.getInstance();
                     this.setIntervall( yearBegin, monthBegin, dayBegin, 
                            yearEnd, monthEnd, dayEnd);
                     this.amountFilled = amountFilled;
  </code></pre>
  
  <p>....</p>
  
  <pre><code>    public void setIntervall(int amountFilled, int yearBegin, int 
      monthBegin, int dayBegin, int yearEnd, int monthEnd, int dayEnd){
         this.begin.set(yearBegin, monthBegin, dayBegin);
         this.end.set(yearEnd, monthEnd, dayEnd);
  </code></pre>
  
  <p>.....</p>