Research on Java collection classes

Source: Internet
Author: User

Test code:

int initialcapacity = 16;
float loadfactor = 0.75f;
hashmap<string,string> HashMap = new hashmap<> (initialcapacity,loadfactor);
System.out.println (Hashmap.put ("1", "V1"));
System.out.println (Hashmap.put ("1", "V2"));

Iterator<string> it = Hashmap.keyset (). Iterator ();
while (It.hasnext ()) {
System.out.println (Hashmap.get (It.next ()));
}

  

    1. //system default initial capacity, must be 2 of the power of N, this is due to optimization considerations
    2. static final int default_initial_capacity = 16;
    3. //system default maximum capacity
    4. static final int maximum_capacity = 1 << 30;
    5. //system default load factor, which can be specified in the constructor
    6. static final float default_load_factor = 0.75f;
    7. //table for storage, length can be adjusted, and must be 2 n power
    8. transient entry[] table;
    9. the Key-value map number of the current map, which is the current size
    10. transient int size;
    11. //Threshold value
    12. int threshold;
    13. //hash Table load factor
    14. final float loadfactor;
    15. //used to ensure that iterators are used, HashMap is not changed
    16. transient volatile int modcount;

HashMap two parameter initialcapacity (Initialize container size), Loadfactor (load factor) in the constructor method

Research on Java collection classes

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.