HashMap source code analysis, hashmap source code

Source: Internet
Author: User

HashMap source code analysis, hashmap source code
In JDK, HashMap is the most common Map implementation based on hash tables. Has the following features:

  • Both key and value are allowed to be null.
  • Non-thread security.
  • Default capacity length: 1 <4 = 16
  • Default maximum capacity: 1 <30
  • Default factor: loadfactor: 0.75f
Implementation of HashMap:
  • Create an array of the specified capacity to store linked list objects
  • Use the hash algorithm to obtain the corresponding hash value for the key of the stored content
  • Take the hash value and length-1 of the array and obtain the subscript of the key in the array.
  • If no linked list object exists at this position, if a new linked list is inserted, null is returned.
  • If a linked list object does not exist at this position and the specified key does not exist, if the content is inserted to the end of the linked list, null is returned.
  • If a linked list object already exists at this position and a specified key exists, replace the content and return the content.
  • Size ++
  • When size> = threshold and the location of the key is not null, scale up. The size is 2 * length * loadfactor.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.