Find objects in a list where some attributes have equal values
<p>Given a list of objects (all of the same type), how can I make sure that it contains only one element for each value of a certain attribute, even though equals() may return false for such elements due to more attributes being checked? In code:</p>

<pre><code>private void example() {
    List&lt;SomeType&gt; listWithDuplicates = new ArrayList&lt;SomeType&gt;();

    /*
     * create the "duplicate" objects. Note that both attributes passed to 
     * the constructor are used in equals(), though for the purpose of this 
     * question they are considered equal if the first argument was equal
     */
    SomeType someObject1 = new SomeObject1("hello", "1");
    SomeType someObject2 = new SomeObject1("hello", "2");

    List&lt;SomeType&gt; listWithoutDuplicates = removeDuplicates(listWithDuplicates)
    //listWithoutDuplicates should not contain someObject2
}

private List&lt;SomeType&gt; removeDuplicates(List&lt;SomeType&gt; listWithDuplicates) {
    /*
     * remove all but the first entry in the list where the first constructor-
     * arg was the same
     */
}
</code></pre>
