In order for the sorted set to work, the elements of the set must be in order. It can be either "natural" (i.e., Elements implement Comparable ), or "imposed" (using an explicit Comparator for a given construction).
So, firstly, you would rather use the order defined for the given elements (after all, you use SortedSet !) Instead of equals in contains for efficiency. I assume that you are already using ordering in your inner SkipListInternal<E> - how do you support Sorted in a SortedSet for equals only?
The fact that contains actually declared as contains(Object key) in the interface is really unsuccessful. I would do what the TreeMap implementation does (which is the base container for TreeSet , the standard SortedSet from the collections framework):
if (comparator != null) return getEntryUsingComparator(key); if (key == null) throw new NullPointerException(); Comparable<? super K> k = (Comparable<? super K>) key;
ie, cast, assuming the client application using your collection is behaving reasonably.
source share