title: Java: How to sort List of Lists by their size?
body: <p>I have 9 different <code>ArrayList</code> and I want to have a list of the top 5. </p>
  
  <p>I'm thinking of sorting those <code>ArrayLists</code> by their sizes. </p>
  
  <p>Is it possible to do that?  If so, how can I achieve that?</p>
  
  <hr>
  
  <p>After a few try i finally got it working, just want to share it with everyone.</p>
  
  <p>it will be better to get the size of the arraylist and add it to the big arraylist</p>
  
  <pre><code>// creates an ArrayList that holds ArrayLists 
  List allTheLists = new ArrayList(); 
  allTheLists.add(pbaustraliaList.size());
  allTheLists.add(pbotherList.size()); 
  allTheLists.add(pbunitedStatesList.size()); 
  allTheLists.add(pbunitedKingdomList.size()); 
  allTheLists.add(pbchinaList.size()); 
  allTheLists.add(pbgermanyList.size()); 
  allTheLists.add(pbindiaList.size()); 
  allTheLists.add(pbjapanList.size()); 
  allTheLists.add(pbsingaporeList.size()); 
  Comparator comparator = Collections.reverseOrder();
  Collections.sort(allTheLists,comparator);
  
  //display elements of ArrayList    
  System.out.println("ArrayList elements after sorting in descending order : ");    
  for(int i=0; i&lt;allTheLists.size(); i++) {     
      System.out.println(allTheLists.get(i));   
  }
  </code></pre>