title: Android how to sort JSONArray of JSONObjects
body: <p>I have made a jsonarray of jsonobjects. Now I need to sort the JSONArray on base of a value from the jsonobjects. Formerly I sorted ArrayLists of custom objects like this:</p>
  
  <p>Comparators:</p>
  
  <pre><code>public class KreeftenComparatorLA implements Comparator&lt;Kreeft&gt; {
      public int compare(Kreeft left, Kreeft right) {
          return left.latijnseNaam.compareTo(right.latijnseNaam);
      }
  }
  public class KreeftenComparatorNL implements Comparator&lt;Kreeft&gt; {
      public int compare(Kreeft left, Kreeft right) {
          return left.naam.compareTo(right.naam);
      }
  }
  </code></pre>
  
  <p>And then sort the arraylist:</p>
  
  <pre><code>Collections.sort(db.lijst, new KreeftenComparatorLA());
  </code></pre>
  
  <p>or:</p>
  
  <pre><code>Collections.sort(db.lijst, new KreeftenComparatorNL());
  </code></pre>
  
  <p>But when I try the same thing with the JSONArray like this (JA = my jsonarray)</p>
  
  <pre><code>Collections.sort(JA, new KreeftenComparatorNL());
  </code></pre>
  
  <p>the Collections.sort gives an error: </p>
  
  <blockquote>
    <p>The method sort(List, Comparator) in the type Collections is not applicable for the arguments (JSONArray, ThisActicity.KreeftenComparatorNL)</p>
  </blockquote>
  
  <p><strong>Does anybody know how to sort the JSONArray?</strong></p>