What are the data structures in Java? How does HashMap work?

Source: Internet
Author: User

Common data Structures in Java

Common data structures are hash tables, linear lists, linked lists, and java.util packages with three important interfaces: List,set,map commonly used to implement basic data structures

How the HashMap works

HashMap based on the hashing principle, we store and retrieve object elements through the put (Key,value) and get (key) methods, and when we pass the key value to the put () method, the Hashcode method of the object element is automatically called to calculate hashcode, Then the location of the object element is determined according to Hashcode.

When we get the object, we find the specific key-value pair entry according to the Equals method of the Key object, and then return the value object;

HashMap uses the list to solve the problem of hash conflict, when a hash conflict occurs, the object is stored on the next node of the list

HashMap is thread insecure, Courrenthashmap is thread-safe (using a segmented lock to lock part of a map)

What are the data structures in Java? How does HashMap work?

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.