Java--hashmap

Source: Internet
Author: User

Today's interview was suddenly asked about the specific implementation of HASHMAP, a face of the feeling of a confused force, usually used is just a direct new a hashmap, and then put (Key,value), get (key) and remove (key) operation, suddenly asked the principle, So I still need to mend it.

Let's start by talking about some common data structures

(1) Array: Array words generally need to open up a continuous space, so occupy a serious memory, space complexity is very large. But it is convenient to find, can use binary search, the complexity is probably O (l). Of course, the delete and insert operations are more complex because the elements need to be moved

(2) linked list: Do not need continuous storage space, can be discretized storage. So the memory is relatively loose, the space complexity is very small. However, finding the words is more complicated and needs to be traversed from head to determine if the elements are needed.

(3) Stack: Stack words are actually extended from the vector, and vector is implements the list of this interface, so in fact, the stack is based on a linked list to achieve. However, due to its particularity, there are only push (object) and pop () two functions, so the time complexity of the operation is also O (1).

(4) HashMap: This is the next point. Since the array is convenient to find, and the storage of the list is convenient, there is no way, can combine the advantages of both. This is how HashMap is implemented.

Java--hashmap

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.