hashCode - the hash value, Object Method, according to the actual situation often rewritten

. 1  Package cn.learn.collection;
 2  
. 3  Import cn.learn.basic.Phone;
 . 4  
. 5  / * 
. 6      hash values: is a decimal integer, is given a random (that is, the address value of the object) by the system, is a logical address, the address is simulated, the physical address of the data is not actually stored
 7      in the ancestor class Object, there is a method to obtain a hash value
 . 8      public int the hashCode ();
 . 9      the hashCode method Source:
 10          public int Native the hashCode ();
 . 11          native representing the method call is the local operating system process
 12 is  
13 is   * / 
14  public  class HashCode_Object {
 15      public  static  void main (String [] args) {
 16         Phone = Phone new new Phone ();
 . 17          int the hash = phone.hashCode ();
 18 is          System.out.println (the hash);    // a decimal integer 793 589 513 
. 19  
20 is          / * 
21          source toString method of Object
 22 is              public String toString () {
 23 is          . getClass return () getName () + "@" + Integer.toHexString (the hashCode ());
 24      }
 25           * / 
26 is          System.out.println (Phone);   // cn.learn.basic.Phone 2f4d3709 @ 
27  
28          / * 
29          hash value of the String class of
 30             String class Object class override hashCode method
 31 is           * / 
32          System.out.println ( "dsasd" .hashCode ());
 33 is          System.out.println ( "DSAD" .hashCode ());
 34 is      }
 35 }

 

Guess you like

Origin www.cnblogs.com/huxiaobai/p/11494155.html