Java record-56-detailed description of implementation of HashSet without repeated Elements

Source: Internet
Author: User

Java record-56-detailed description of implementation of HashSet without repeated Elements
Detailed description of HashSet Implementation of HashSet without repeated elements: public boolean add (E e) If this set does not contain the specified element, add the specified element. More specifically, if this set does not contain meet (e = null? E2 = null: e. equals (e2) element e2, then add the specified Element e to this set. If this set already contains this element, the call does not change the set and returns false. The equals method of an Object: public boolean equals (Object obj) indicates whether another Object is "equal" to this Object ". The equals method achieves equality on non-null object references: Inversion: returns true for any non-null reference values x and x. equals (x. Symmetry: For any non-null reference values x and y, x. equals (y) returns true only when y. equals (x) returns true. Passed: For any non-null reference values x, y, and z, if x. equals (y) returns true, and y. equals (z) returns true, then x. equals (z) should return true. Consistency: For any non-null reference values x and y, call x multiple times. equals (y) always returns true or false, provided that the information used in the equals comparison on the object is not modified. Returns false for any non-null reference value x, x. equals (null. The equals method of an Object implements the maximum possible equality relationship between objects. That is, for any non-null reference values x and y, if and only when x and y reference the same Object, this method returns true (x = y has a value of true ). Note: When this method is overwritten, it is usually necessary to override the hashCode method to maintain the conventional protocol of the hashCode method, which declares that equal objects must have equal hash codes.

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.