Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on the <code>Set</code> implementation. For <code>HashSet</code> and <code>LinkedHashSet</code>, it uses both <code>equals</code> and <code>hashCode</code> methods. For <code>TreeSet</code>, it uses the natural <code>Comparator</code> of the object or a specific provided <code>Comparator</code>.</p> <p>Basically, the <a href="http://docs.oracle.com/javase/7/docs/api/java/util/Set.html" rel="nofollow"><code>Set</code> javadoc</a> explains this (emphasis mine):</p> <blockquote> <p>A collection that contains no duplicate elements. More formally, <strong>sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element</strong>. As implied by its name, this interface models the mathematical set abstraction.</p> <p>The Set interface <strong>places additional stipulations</strong>, beyond those inherited from the Collection interface, on the contracts of all constructors and on the contracts of the add, <strong>equals and hashCode methods</strong>.</p> </blockquote> <p><code>TreeSet</code> has another behavior since it implements <a href="http://docs.oracle.com/javase/7/docs/api/java/util/SortedSet.html" rel="nofollow"><code>SortedSet</code></a> (this interface extends the <code>Set</code> interface). From its javadoc (emphasis mine):</p> <blockquote> <p>A Set that further provides a total ordering on its elements. The elements are ordered using their natural ordering, or by a Comparator typically provided at sorted set creation time. The set's iterator will traverse the set in ascending element order.)</p> <p>Note that the ordering maintained by a sorted set (whether or not an explicit comparator is provided) must be consistent with equals if the sorted set is to correctly implement the Set interface (See the Comparable interface or Comparator interface for a precise definition of consistent with equals.) This is so because <strong>the Set interface is defined in terms of the equals operation, but a sorted set performs all element comparisons using its compareTo (or compare) method.</strong></p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload