title: How to get date of all days in past week?
body: <p>I have an application in which every Sunday, it checks a MySQL database for data from the past week.  I am trying to find out how to get the date String for each day of the past week.  My obvious first attempt was:</p>
  
  <pre class="lang-java prettyprint-override"><code>Calendar calendar = Calendar.getInstance();
  
  if(calendar.DAY_OF_WEEK == 7){
  
      java.sql.Date date = new java.sql.Date(calendar.getTime().getTime());
  
      String dates[] = new String[7];
  
      for(int i; i &lt; 7; i++){
          dates[i] = date.substring(0,7) + date.substring(7, date.length());
      }
  
      // Now grab data from the database where the date corresponds with one of these.
  }
  </code></pre>
  
  <p>Today, this would work.  However, if it were the 1st through the 6th of a month, this would not work as it wouldn't account for the change in month.  Is there a way to get around this.  I'm sure somebody has done a similar thing.  Thanks.</p>