-3

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

farm ostrich
  • 5,671
  • 14
  • 52
  • 79

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,110
  • 14
  • 78
  • 114
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
  • 53,024
  • 17
  • 128
  • 180
Kane
  • 3,697
  • 2
  • 22
  • 32
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
  • 26,896
  • 8
  • 84
  • 93
  • 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