title: How to Convert String into Date Java
body: <p>I currently have an <code>ArrayList</code> filled with dates in the format <code>2012-06-19</code> and I am trying to add them all to an array of <code>Date</code>s.</p>
  
  <p>This is the portion of code that is failing me,</p>
  
  <pre><code>    listIterator = dateValues.listIterator();
  
      Date [] dates = new Date[dateValues.size()];
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
      int i = 0;
      try{
          while(listIterator.hasNext())
          {
              //System.out.println(listIterator.next().toString());
              dates[i] =  dateFormat.parse(listIterator.next().toString());
              i++;
  
          }
  
          for(i = 0; i &lt; dates.length;i++)
          {
              System.out.println(dates[i]);
          }
      }
      catch(Exception e){e.printStackTrace()};
  }
  </code></pre>
  
  <p>The line</p>
  
  <pre><code>//System.out.println(listIterator.next().toString());
  </code></pre>
  
  <p>will print out every date in the ArrayList. Output looks like,</p>
  
  <pre><code>2007-09-07
  2007-09-07
  2007-10-05
  2007-10-05
  2007-10-05
  2007-10-05
  2007-10-05
  </code></pre>
  
  <p>but my <code>dateFormat</code> line never adds any values to <code>dates[]</code>. Any help would be appreciated. </p>
  
  <p>And no, it isn't homework. </p>