= =, equals and hashcode

Source: Internet
Author: User

==

First, you have to explain that the Java data types are divided into basic data types and reference data types.

There are 8 types of basic data:

Float type: float (4 byte), double (8 byte)

Integer: Byte (1 byte), short (2 byte), int (4 byte), Long (8 byte)

Character type: char (2 byte)

Boolean Type: Boolean

When compared by using the base data type, the actual value is compared, compared with the reference data type, and the address stored in memory is compared.

-----------------------------------------------------------------------------------

equals

First, Equals is the method defined in the class, not the same Equals method

eg

Object class

 Public boolean equals (Object obj) {  return (this = = obj);  }

Visible for object,equals and = = Consistent

For other classes, the Equals method is overridden to determine whether the values are equal .

For example, the string class overrides the Equals method to compare whether strings stored by a pointed string object are equal.

-----------------------------------------------------------------------------------

Hashcode

Here is a brief introduction to the hash table, note the following three words: Key keyword, mapping relationship f (key) also known as hash function, hash value

Hashing technology is to establish a deterministic relationship between the storage location of the record and its key words, the keyword key through the mapping relationship f (key) to derive the hash value, that is, the storage location, the storage location is a contiguous storage space, called a hash table .

The Hashcode method is to map the object-related information (such as the object's storage address, the object's field, and so on) to a numeric value according to certain rules.

If two objects hashcode the same, does not mean that they are really equal, you have to confirm with equals again

If two objects hashcode different, it means they are not equal.

= =, equals and hashcode

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.