The hashCode() method of java.lang.reflect.Field used to get the hashcode for this Field. Final Hashcode is computed as the exclusive-or of the hashcodes for the underlying field’s declaring class name and its name. The hashcode is always the same if the object doesn’t change. Hashcode is a unique code generated by the JVM at the time of object creation. It can be used to perform some operation on hashing related algorithm like a hashtable, hashmap etc. An object can also be searched with this unique code.
public int hashCode()
Parameters: This method accepts nothing.
Return value: This method returns an integer which is the hash code value for this object.
Below programs illustrate hashCode() method:
HashCode of Marks field is 71482573 HashCode of Fees field is 591398 HashCode of name field is 1779040
HashCode of Field: -297508095 HashCode of Field: 1296412905 HashCode of Field: 1475695976 HashCode of Field: 1343692077 HashCode of Field: 1404020238 HashCode of Field: 1401709321 HashCode of Field: 1401709395 HashCode of Field: 538235208 HashCode of Field: 2125827066 HashCode of Field: -1718938229 HashCode of Field: -1007182215 HashCode of Field: 59532142
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.