
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What Does the Method hashCode() Do in Java
The hashCode(Object[]) method of the java.util.Arrays class returns a hash code based on the contents of the specified array. If the array contains other arrays of elements, the hash code is based on their identities rather than their contents. For any two arrays a and b such that Arrays.equals(a, b), it is also the case that Arrays.hashCode(a) == Arrays.hashCode(b).
Example
import java.util.Arrays; public class ArrayDemo { public static void main(String[] args) { Object[] ob = new Object[] { 22, 7 }; int retval = ob.hashCode(); System.out.println("The hash code of value1 is: " + retval); ob = new Object[] { 3.5, 8.5 }; retval = ob.hashCode(); System.out.println("The hash code of value2 is: " + retval); } }
Output
The hash code of value1 is: 4072869 The hash code of value2 is: 1671711
Advertisements