When i run the method Hashcode() of an instance object in JAVA, it returns a negative value which seems to be odd! Does any body know why? Because i am using Hashcode as Hashvalue in the hashtable.
posted 13 years ago
Well, why shouldn't negative values be allowed? They're just numbers. It doesn't matter if they're negative or not. Allowing them to be negative means that we can have 2^32 possible values using 4-byte data types, rather than 2^31. (Since Java does not generally support the concept of unsigned types as found in other languages like C/C++).
Basically, hashcodes can be negative because there's no reason not to allow them to be negative. I can't really think of a better way to say it, so I hope that helps...