title: How to use a Java8 lambda to sort a stream in reverse order?
body: <p>I'm using java lambda to sort a list.</p>
  
  <p>how can I sort it in a reverse way?</p>
  
  <p>I saw this <a href="https://stackoverflow.com/questions/5894818/how-to-sort-arraylistlong-in-java-in-decreasing-order">post</a>, but I want to use java 8 lambda.</p>
  
  <p>Here is my code (I used * -1) as a hack</p>
  
  <pre><code>Arrays.asList(files).stream()
      .filter(file -&gt; isNameLikeBaseLine(file, baseLineFile.getName()))
      .sorted(new Comparator&lt;File&gt;() {
          public int compare(File o1, File o2) {
              int answer;
              if (o1.lastModified() == o2.lastModified()) {
                  answer = 0;
              } else if (o1.lastModified() &gt; o2.lastModified()) {
                  answer = 1;
              } else {
                  answer = -1;
              }
              return -1 * answer;
          }
      })
      .skip(numOfNewestToLeave)
      .forEach(item -&gt; item.delete());
  </code></pre>