title: Create from a List<Date> a List<List<Date>> that has all Dates which are subsequently put in Lists
body: <p>I hope you understood me. Hard to describe in english for me.
  So I have a List of sorted Date Objects. Now I want to put all Dates that are in a row  (12/16/09, 12/17/09, 12/18/09...) in a List of their own. Stand-alone-Dates shall also be put in a List of their own.</p>
  
  <p>So from <code>(12/01/09; 12/02/09; 12/03/09; 12/06/09; 12/10/09; 12/17/09; 12/18/09; 12/31/09)</code>
  I want to create</p>
  
  <pre><code>[(12/01/09; 12/02/09; 12/03/09)(12/06/09)(12/10/09)(12/17/09; 12/18/09)(12/31/09)]
  </code></pre>
  
  <p>The code I have works. But it is so complicated I was wondering if maybe there is an easier way. Unfortunately I can't use Joda-Time. maybe someone has done it before...</p>
  
  <pre><code>public List&lt;List&lt;Date&gt;&gt; listOfDatestoList(List&lt;Date&gt; dates){
  
      List&lt;List&lt;Date&gt;&gt; list = new ArrayList&lt;List&lt;Date&gt;&gt;();
  
      List&lt;Date&gt; theseDates = new ArrayList&lt;Date&gt;();
  
  
      if(dates.size() == 1){
          theseDates.add(dates.get(0));
          list.add(theseDates);
          return list;
      }
  
      for (int i = 0; i &lt; dates.size() - 1; i++) {        
          Calendar cal1 = Calendar.getInstance();
          Calendar cal2 = Calendar.getInstance();
  
          //Die ersten beiden Daten der Liste werden verglichen
          cal1.setTime(dates.get(i));
          cal2.setTime(dates.get(i + 1));
  
          cal1.add(Calendar.DAY_OF_YEAR, 1);
  
  
          if(cal1.equals(cal2)){
              theseDates.add(dates.get(i));
          }
  
          else if(theseDates.size() &gt; 0){
              theseDates.add(dates.get(i));
  
              List&lt;Date&gt; tempList = new ArrayList&lt;Date&gt;();
              for(Date date : theseDates){
                  tempList.add(date); 
              }
              list.add(tempList);
              theseDates = new ArrayList&lt;Date&gt;();
          }
          else{
              List&lt;Date&gt; tempList = new ArrayList&lt;Date&gt;();
  
              tempList.add(dates.get(i));
              list.add(tempList); 
          }
  
          if(i == dates.size() - 2){
  
              if(cal1.equals(cal2)){
                  theseDates.add(dates.get(i + 1));
              }
  
              if(theseDates.size() &gt; 0 ){
                  list.add(theseDates);
                  theseDates = new ArrayList&lt;Date&gt;();
              }
              else{
                  List&lt;Date&gt; tempList = new ArrayList&lt;Date&gt;();
                  tempList.add(dates.get(i+1));
                  list.add(tempList);
              }
  
          }
      }
      return list;
   }  
  </code></pre>