Map in Java

Source: Internet
Author: User

The commonly used map implementation classes in Java include: HashMap, HashTable, TreeMap.

One: HashMap

The bottom of the HashMap is actually the "array of linked lists", that is, each element actually holds a linked list, and the linked list holds objects with the same hash value.

1: New HashMap, is actually a new array

 PublicHashMap (intInitialcapacity,floatloadfactor) {//Initialcapacity represents the capacity of the initialized HashMap, its maximum capacity is maximum_capacity = 1 << 30.         if(Initialcapacity < 0)            Throw NewIllegalArgumentException ("Illegal initial capacity:" +initialcapacity); if(Initialcapacity >maximum_capacity) initialcapacity=maximum_capacity; //Loadfactor represents its load factor, the default is default_load_factor=0.75, which is used to calculate the threshold critical value.         if(loadfactor <= 0 | |Float.isnan (loadfactor))Throw NewIllegalArgumentException ("Illegal load factor:" +loadfactor); //Find a power of 2 >= initialcapacity        intCapacity = 1;  while(Capacity <initialcapacity) Capacity<<= 1;  This. Loadfactor =Loadfactor; Threshold= (int) (Capacity *loadfactor); Table=NewEntry[capacity];    //create array init (); }

2: Inserting elements

Map in Java

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.