Arraylist,hashmap,linkedlist initialization size and scaling mechanism

Source: Internet
Author: User

Don't want to talk. Look directly at the implementation class. 1.ArrayList

ArrayList initialization size is 10 (if you know how much capacity your ArrayList will reach, it can be specified at initialization time, which can save the performance cost of expansion)
Expansion point rule is, the new time to find that the capacity is not enough, to expand
The expansion size rule is that the size after expansion = original size + Original size/2 + 1. (Example: The original size is 10, the size after expansion is ten + 5+1 = 2.linkedList )

LinkedList is a doubly linked list, no initialization size, no capacity expansion mechanism, is always in front of or behind the new is good.
Understanding of doubly linked lists
3.HashMap

HashMap initialization size is 16, expansion factor default 0.75 (can specify initialization size, and expansion factor)
Expansion mechanism. (The current size and current capacity ratio exceeds the expansion factor, will be expanded, the size is one-fold after expansion.) For example: The initial size is 16, the expansion factor is 0.75, when the capacity is 12, the ratio is already 0.75. Trigger expansion, the size after expansion is 32.)

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.