title: String to Date Conversion and Date arithmetic
body: <p>I have a list of strings in my java application that represent dates. The format is yyyy/MM/dd. I want to be able to take all of these strings and convert them to actual date objects so arithmetic can be performed on them. </p>
  
  <p>Basically I want to go through the list and remove dates that have already occurred. I have attached the code.</p>
  
  <pre><code>List&lt;String&gt; datesList = new ArrayList&lt;String&gt;();
          datesList.add("2011-11-01");
          datesList.add("2015-11-01");
  
          //Get todays date and format it 
          Calendar currentDate = Calendar.getInstance(); 
          SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd"); 
  
          //This string will also need to be converted to a date object so the loop arithmetic can be performed.
          String today = formatter.format(currentDate.getTime());
          System.out.println(today);
  
          for(String date: datesList) {
              //The list cannot change from a list of strings.
              //So the conversion will probably have to take place in this loop.
              System.out.println(date);
              //if(date &lt; today) ...
              //datesList.remove(date);
          }
  </code></pre>
  
  <p>Updating to include solution:</p>
  
  <pre><code>List&lt;String&gt; datesList = new ArrayList&lt;String&gt;();
          datesList.add("2013-11-01");
          datesList.add("2011-11-01");
          datesList.add("2013-04-29");
          datesList.add("2001-05-19");
  
          SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd"); 
  
          List&lt;String&gt; validDatesList = new ArrayList&lt;String&gt;();
  
          for(String date: datesList) {
              Date listItem = formatter.parse(date);
              Date todayDate = new Date();
  
              if(todayDate.after(listItem)) {
                  System.out.println(listItem+" has already happened because today is "+todayDate);
              } else{
                  validDatesList.add(date);
              }
          }
  
          for(String validDate: validDatesList) {
              System.out.println("Valid date: "+validDate);
          }
  </code></pre>
  
  <p>Thanks.</p>