Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How hashMap internally works in java ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 547
    Comment on it

    It’s not wrong to say that HashMap is an implementation of Map interface as it allows value storing in key value pairs. Although unique elements are present in Hashmap, null values and only one null key are allowed.

    Hashmap basically works on the principal of Hashing.

    It contains 3 terms like hashCode() function that is used to return some integer value, this value is called as a hash value and a bucket.

     

    Hashmap provides two methods that are:

    put(key,value) - to insert value on given key

    get(key) - to access value from given key

     

    Hashmap provides put method to insert some value on given key but this a hashCode() function internally works on that key to calculate a hash that is used to find a matched bucket with that hash value to insert record.

    when get is used then again hashCode() function calculate a hashvalue to find the bucket where the key is stored.

    But in case if two keys have the same value then equals method is used to compare all keys in each entries to find the correct match.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: