 <p>You could have your <code>Line</code> object implement the <a href="http://java.sun.com/javase/6/docs/api/java/lang/Comparable.html" rel="nofollow noreferrer"><code>Comparable</code></a> interface. You could then put the comparison logic within the <code>Line</code> class in the <code>compareTo</code> method. The logic there will test whether the slope and the intercept match, and if so return <code>0</code>. Other results could return <code>1</code> or <code>-1</code> to enforce ordering, if you want.</p> <p>Obviously, you don't need to implement this interface to effect your desired results. However, as this is homework, doing so will allow you to play around with some features of the JDK, like using sorted Lists, etc. With a sorted list, for example, you could obviate the need for a nested loop, as you would only need to compare the object in question against one you just removed from the <code>Iterator</code> in the previous iteration to see if you need to add it to an existing linelist or start a new one.</p>