-3

I can't seem to find it. What is it? THANKS!

farm ostrich
  • 5,881
  • 14
  • 55
  • 81

3 Answers3

4

Set does not generate any hashcodes. It depends on hashcodes defined for the objects put into the Set.

Any class can override public int hashCode().

Paul Croarkin
  • 14,496
  • 14
  • 79
  • 118
2

If you look at the source for Object you can see this is done in native code. The Set interface just calls hashCode() on the objects in the set.

Paul Bellora
  • 54,340
  • 18
  • 130
  • 181
Kane
  • 4,047
  • 2
  • 24
  • 33
1

As "Set" is just an interface, the hashcode will be generated by the actual implementation you're using, e.g. HashSet or TreeSet (or actually, AbstractSet).

ziesemer
  • 27,712
  • 8
  • 86
  • 94
  • Bhesh - you're probably right - though I guess there were 2 different ways to read the question: The hash code generation of the Set itself, or how the Set generates hashcodes for its objects - the later of which would only be applicable if using HashSet, which isn't mentioned. Maybe the OP can clarify the request? – ziesemer Nov 21 '11 at 19:47
  • Your point absolutely makes sense. Problem is with the OP's body which is not even the half of the title itself. – Bhesh Gurung Nov 21 '11 at 20:03