title: Android sorting optimization
body: <p>I am working on an Android app.  I want to implement a function that when clicking a button the data （files with their sizes）shown on the screen is sorted. Here I sort the files by file sizes using <code>Comparator&lt;&gt;</code> in android:  Comparator <code>ascSort</code> and Comparator <code>descSort</code>, then return them into <code>Collections.sort()</code> and decide the sorting order by the boolean value of <code>isClick</code>. <code>FileMangeBean</code> is a bean of file data that allows calling <code>getFileSize()</code>.</p>
  <p>Here is the problem: Is there any approach to optimize the sorting, like merging <code>ascSort</code> and <code>descSort</code> into one <code>Sort</code>?<br />
  Also, welcome to provide more ideas on sorting data(files) by their sizes in android if you have.</p>
  <pre><code>switch(...){
      case R.id.file_size_sort_button:
          isClick = !isClick;     // boolean value: isClick 
          
          // display files ascendingly or descendingly in size
          Collections.sort(fileSizeData, isClick ? ascSort : descSort);    
          
          // set an icon according to isClick 
          aImageView.setImageResource(isClick ? R.drawable.close_icon : R.drawable.open_icon);
  </code></pre>
  <pre><code>private Comparator&lt;FileManageBean&gt; descSort = (o1, o2) -&gt; {
      long size1 = o1.getFileSize();
      long size2 = o2.getFileSize();
      return Long.compare(size2, size1);
  };
  
  private Comparator&lt;FileManageBean&gt; ascSort = (o1, o2) -&gt; {
      long size1 = o1.getFileSize();
      long size2 = o2.getFileSize();
      return Long.compare(size1, size2);
  };
  </code></pre>