title: Compare dates from a String in list
body: <p>I'm having a problem continuing. I have a list and in each position contains a String (within the phrase there is at the end a date) </p>
  
  <p>Example: </p>
  
  <pre><code>I am new here 20/8/2019 
  </code></pre>
  
  <p>I want to sort the list this way:
  In position zero I want the phrase containing the oldest date and the following positions the date will be more recent. </p>
  
  <p>I tried to use SimpleDateFormat and Date, but I didn't know how to do it.</p>
  
  <pre><code>String variable, variable2, c;
  int d = 0;
  for(int i = 0; i &lt; lista.size(); i++) {
      for(int j = 1; j &lt;lista.size(); j++) {
          variable = lista.get(i);
          variable2 = lista.get(j);
          c = compareDates(variable, variable2);
          lista.add(d,c);
          d++;
      }
  }
  
  private static Date compareDates(String variable, String variable2) throws ParseException {
      SimpleDateFormat formateador = new SimpleDateFormat("dd/MM/yyyy");
      String var = formateador.format(variable);
      String var2 = formateador.format(variable2);
      if (var.before(var2)) {
          return var;
      } else {
          if (var2.before(var1)) {
  
          } else {
  
          }
          return null;
      }
  }
  </code></pre>
  
  <p>Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
      Type mismatch: cannot convert from Date to String</p>
  
  <pre><code>at Ejercicio.ClaseMain.leerDes(ClaseMain.java:124)
  </code></pre>
  
  <blockquote>
    <p>Line 124: c = compareDates(variable, variable2);</p>
  </blockquote>
  
  <p>Visual example: Each position in the list has a phrase with a date:</p>
  
  <p><a href="https://i.stack.imgur.com/4Q93C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Q93C.png" alt="enter image description here"></a></p>
  
  <p>The thing is, I read a .txt file, where there are several lines.
  Contents of the file:</p>
  
  <blockquote>
    <p>Sevilla reserves himself to Apoel and wins without brilliance; sport
    Julen Lopetegui revolutionized the eleven with the aim of giving rest
    to the regulars, which did not prevent his team from adding his second
    triumph of the competition sportyou 10/10/2019</p>
    
    <p>A painting by Banksy of the British Parliament occupied by chimpanzees, sold >for 11 million
    euros culture An oil of artist Banksy representing the British House
    of Commons full of chimpanzees was topped on Thursday at an auction in
    London for 9.8 million pounds (11 million euros) 10/2019</p>
  </blockquote>
  
  <p>I use a while to read the file line and save each line at each position in the list, and I want to sort the list. Old date ---> recent date.</p>