Results 1 to 6 of 6

Thread: What is hashCode?

  1. #1

  2. #2
    Registered
    Join Date
    Mar 2016
    Posts
    76
    Hash Code is used for bucketing in hash implementation like hashmap, hashtable, hashset...

  3. #3
    Registered pxljobs's Avatar
    Join Date
    Jul 2016
    Location
    Bangalore
    Posts
    290
    Hash code is a code that identifies each object,not necessarily unique hash code is generally used for comparing objects, if two object of same type can have same hash code they said to be equal hash code is integer value this would be automatically generated by JVM.

  4. #4
    Registered
    Join Date
    Feb 2017
    Posts
    10
    Hi, HashCode is a mathematical formula that returns some integer value. This integer value is used as index in array.

    Thanks!

    _____
    secdevops

  5. #5
    Registered
    Join Date
    Jan 2017
    Posts
    55
    A hashcode is a number generated from any object. This is what allows objects to be stored/retrieved quickly in a Hashtable. Imagine the following simple example: On the table in front of you you have nine boxes, each marked with a number 1 to 9.

    Thank you~

    HAPPY TO HELP YOU!

  6. #6
    Junior Registered
    Join Date
    Feb 2017
    Posts
    4
    HashCode is a mathematical formula(there is no best hash function) that returns some integer value.
    This integer value is used as index in array.
    Example
    hashCode(int value){

    /*Some hash function computation goes here*/
    return hash;
    }

    The hash is returned and now it acts as the index of the array. The value is inserted in that place. Now if you want to retrieve that value then you again use hashCode(val) and get the hash of value and directly take that value from index of array.

    Well what happens if hashCode(val) returns index where the value is already inserted. This is called collision and some collision handling strategy is used(example separate chaining).

    Qualities of good hash function
    For same value the Hash function should return same hash
    hash function should distributed the hash evenly across the array.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •