title: Sort an ArrayList by subclasses in Java
body: <p>so I am trying to sort an ArrayList as the title says. I have A Superclass called <code>Thing</code> that has 2 different subclasses, a <code>HeavyThing</code> and a <code>LightThing</code>. The ArrayList contains just the 2 subclasses and I need to sort it so the <code>HeavyThing</code> comes before the <code>LightThing</code>.
  So far I got the sort method to work for the name of the Things but I was unable to sort it by subclass.</p>
  <pre><code>        this.collThings.sort(new Comparator&lt;Thing&gt;() {
              public int compare(Thing t1, Thing t2) {
                  return Integer.valueOf(t1.getName().compareTo(t2.getName()));
              }
          });
  </code></pre>
  <p>This is how I sorted it by name.</p>