Java Foundation 11th Day Summary

Source: Internet
Author: User
Tags set set

Hash hash,

When adding objects, first determine whether the hashcode of two objects is the same, if different, directly add, if the same, then judge the Equals method, if different directly add Equls the main function is to compare the contents of the object. If it is different, it can be added regardless of whether it is the same object.

Equals is to determine whether the object content is equal

Hashcode

HashSet HashMap can not store duplicate elements, judge the standard.

Judge Hashcode and judge the Equals method first.

Hashcode can be added directly, even if the same object can be added.

The second condition is the Equals method, and the return value is a Boolean value. Determines whether the value of the object is the same.

The advantage is the speed of the retrieval.

HashSet: Thread insecure, fast access speed, how unique it is.

TreeSet: Thread is unsafe, you can sort the elements in the set collection.

Element uniqueness is ensured through the CompareTo Comapre method.

Features of generics:

Map collection is different from collection? Parallel presence

Map fastidious is kv to key-value---->entry (entry)

Key (Key)--value (value)

Map.put collection is using the add

The map element does not have a way to take the element directly, and it is first converted to set and then taken out of the iteration to fetch the corresponding value.

All keys are in a set, and the values in the set cannot be duplicated.

The set Set=map.keyset () return value must be a collection.

Map.get (key) Gets the value in the map.

The uniqueness of the elements is guaranteed in the Map collection.

Java Foundation 11th Day Summary

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.