Sunday 15 August 2010

java - Are there any constraints on the hash map data type -


Is there a hindrance on the key type in the hash map and hash tables? ---- Interview question I think we can customize it as necessary.

Technically, not usually, you want to use an object that is equal to ( ) And Hashod () applies although it is not strictly necessary. If you do not, then it will use the base implementation set by the object which compares the object identification. Many times, this is not suitable, but sometimes it's okay.

Technically, the key is not required to be irreversible, as long as the values ​​used in the (and) hash code () implementation are irreversible. For example, if your class uses Foo string as a part of "foo" then that value should not be changed to "foo", that is because hash maps have the basis for the hash code () values ​​for efficiency reasons But the keys are put in the left. If the hashcode suddenly changes, the hash map is unknown and the key now lives in the wrong bucket and you will get into the dirty bug because your map can have "duplicate" objects. Hope this makes sense.

No comments:

Post a Comment