Java Basic article

Source: Internet
Author: User

1. The difference between "= =" and "Equeal"

The Hashcode method returns the hash code value of the object. This method is supported to provide some advantages to the hash table, for example, the Hashtable provided by Java.util.Hashtable. The general contract for Hashcode is that during Java application execution, when the Hashcode method is called multiple times on the same object, the same integer must be returned consistently, provided that the information used in the Equals comparison on the object has not been modified. The integer does not need to be consistent from one execution of an application to another execution of the same application. If two objects are equal according to the Equals (object) method, calling the Hashcode method on each object in two objects must produce the same integer result. The following conditions are not required: If two objects are not equal according to the Equals (Java.lang.Object) method, then calling the Hashcode method on any of the two objects must produce a different integer result. However, programmers should know that generating different integer results for unequal objects can improve the performance of the hash table. In fact, the Hashcode method defined by the object class does return different integers for different objects. (This is typically done by converting the object's internal address to an integer, but the JAVATM programming language does not require this implementation technique.) When the Equals method is overridden, it is often necessary to override the Hashcode method to maintain the general contract of the Hashcode method, which declares that the equality object must have an equal hash code.

  
1  Public Static voidMain (string[] args) {2         intI=0;3         intm=i;4M=m+1;5 System.out.println (i);6 System.out.println (m);7         8String a= "0";9String b=A;Tenb= "1"; One System.out.println (a); A System.out.println (b); -          -Moneychangerequest MoneyChangeRequest1 =Newmoneychangerequest (); theMoneychangerequest1.setcardno ("1"); -Moneychangerequest MoneyChangeRequest2 =Newmoneychangerequest (); -Moneychangerequest2.setcardno ("1"); -          +System.out.println (Moneychangerequest1.getcardno (). Hashcode () = =Moneychangerequest2.getcardno (). Hashcode ()); -}

Java Basic 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.