PANKAJ SHET
B.Sc.(I.T.), S.C.J.P., S.C.W.C.D., PGDAC(CDAC)
Steve
PANKAJ SHET
B.Sc.(I.T.), S.C.J.P., S.C.W.C.D., PGDAC(CDAC)
Steve
PANKAJ SHET
B.Sc.(I.T.), S.C.J.P., S.C.W.C.D., PGDAC(CDAC)
Steve Luke wrote:It depends on the Set implementation.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Steve Luke wrote:It depends on the Set implementation.
Actually, it isn't - or it shouldn't be - because Sets are not supposed to allow duplicates at all.
Specifically, the java.util.Set docs clearly defines it as:
A Collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element.
Steve
Steve Luke wrote:And yet TreeSet uses compareTo() or the Comparator's compare() methods, not its equals method...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
Steve Luke wrote:And yet TreeSet uses compareTo() or the Comparator's compare() methods, not its equals method...
Because it is a SortedSet, whose docs clearly state:
Steve
Steve Luke wrote:Correct, but a SortedSet Is A Set (inherits from). So saying a Set depends solely on equals() ignores those Sets which don't.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:@Pankaj: which means that "duplicate" depends solely on how your objects implement equals() (and possibly hashCode() - also detailed in the docs), not on how the Set itself is implemented.
Steve
Steve Luke wrote:So I think my original statement "It depends on the Set implementation" is correct.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |