title: how can i get last 7 days from current day in ascending order in java?
body: <p>I am using following code to get the last 7 days:</p>
  
  <pre><code>SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");
  Calendar cal = Calendar.getInstance();
  Date date = cal.getTime();
  String[] days = new String[6];
  days[0] = sdf.format(date);
  
  for(int i = 1; i &lt; 6; i++){
      cal.add(Calendar.DAY_OF_MONTH, -1);
      date = cal.getTime();
      days[i] = sdf.format(date);
  }
  
  for(String x: days){
      System.out.println(x);
  }
  </code></pre>
  
  <p>And this is giving the following output:</p>
  
  <pre><code>2016-04-14
  2016-04-13
  2016-04-12
  2016-04-11
  2016-04-10
  2016-04-09
  </code></pre>
  
  <p>But I want this instead:</p>
  
  <pre><code>2016-04-09
  2016-04-10
  2016-04-11
  2016-04-12
  2016-04-13
  2016-04-14
  </code></pre>
  
  <p>If I use the following line below the code it will give me the correct order:</p>
  
  <pre><code>List&lt;String&gt; list = Arrays.asList(days);
  Collections.reverse(list);
  days = (String[]) list.toArray();
  
  for(String x: days){
      System.out.println(x);
  }
  </code></pre>
  
  <p>But is there any other way to get the last 7 days in ascending order in one shot?</p>