title: How to sort an arrayList of objects by their components in java
body: <p>I am trying to sort an arrayList in two different ways, one by the areas of the objects inside the arrayList, and two, by the name(shape1, shape2) of the objects in the arrayList. The objects look like this when I print them into a file: shape1: (points, radius, etc...) area = 0.0 and the shapes keep going. I tried looking at other asked questions that are similar but all answered using Collections.sort. I am not sure I am supposed to be using this method. Here's some code I'm working with to give you an idea:</p>
  
  <pre><code>for (int i =0; i &lt;shapes.size();i++){
      for (int j = 1; j&lt;shapes.size(); j++){
          if (shapes.get(i).getShape().area() &gt; shapes.get(j).getShape().area())
          {
              //
          }
          else
          {
              //
          }
      }
  }
  </code></pre>
  
  <p>I'm not sure how I should go about doing this. Any pointers? For the sorting by name I have to use:</p>
  
  <pre><code>shapes.get(i).getName()
  </code></pre>