I want to be able to have LinkedList.contains() return true for a custom comparator.
Suppose that I have 1 LinkedList and 2 objects
LinkedList
The documentation for the contains method is as follows:
Returns true if this collection contains the specified element. More formally, returns true if and only if this collection contains at least one element e such that (o==null ? e==null : o.equals(e)).
Therefore, you need to override the MyObject's equals(Object o) method.
So for your example:
public class MyObject {
String myVal;
public boolean equals(Object o ) {
return ((MyObject)o).myVal.equals(myVal);
}
}
You do not need to implement anything with the Comparable interface.