Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Hash Code

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hash Code

    anyone please tell me that what is mean by hash code??


  2. #2
    Junior Member
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hash Code

    Hashcode is used for bucketing in Hash implementations like HashMap, HashTable, HashSet etc. The value received from hashcode() is used as bucket number for storing elements of the set/map. this bucket number is the address of the element inside the set/map. when you do contains() then it will take the hashcode of the element, then look for the bucket where hashcode points to... if more than 1 element is found in the same bucket (multiple objects can have the same hashcode) then it uses the equals() method to evaluate if object are equal, and then decide if contain() is true or false, or decide if element could be added in the set or not.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Hash Code

    Hashtable was part of the original java.util and is a concrete implementation of a Dictionary.

    Like HashMap, Hashtable stores key/value pairs in a hash table. When using a Hashtable, you specify an object that is used as a key, and the value that you want linked to that key. The key is then hashed, and the resulting hash code is used as the index at which the value is stored within the table.

    The Hashtable defines four constructors. The first version is the default constructor:

    Hashtable( )
    The second version creates a hash table that has an initial size specified by size:

    Hashtable(int size)
    The third version creates a hash table that has an initial size specified by size and a fill ratio specified by fillRatio.

    This ratio must be between 0.0 and 1.0, and it determines how full the hash table can be before it is resized upward.

    Hashtable(int size, float fillRatio)
    The fourth version creates a hash table that is initialized with the elements in m.

    The capacity of the hash table is set to twice the number of elements in m. The default load factor of 0.75 is used.

    Hashtable(Map m)

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,431
    Thanks
    191
    Thanked 844 Times in 786 Posts
    Blog Entries
    5

    Default Re: Hash Code

    Recommended reading:
    Object (Java Platform SE 7 )
    Please make an effort to research your questions using books or online resources before posting them. The effort of the unpaid volunteers of this forum are much better spent answering any questions that you may have after you've done the research.

Similar Threads

  1. Need help with hash tables in my code
    By sarbu_192 in forum Java Theory & Questions
    Replies: 2
    Last Post: February 11th, 2014, 05:50
  2. Summing values in hash table
    By akerman in forum Java Theory & Questions
    Replies: 9
    Last Post: November 13th, 2013, 13:55
  3. Hash Functions
    By Blueshark in forum Java Theory & Questions
    Replies: 3
    Last Post: July 2nd, 2012, 15:04
  4. hash table probes
    By victorh in forum Collections and Generics
    Replies: 4
    Last Post: November 7th, 2011, 23:33
  5. hash map iteration
    By uniqe_mohini in forum Member Introductions
    Replies: 2
    Last Post: September 10th, 2011, 10:14