- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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(obj[] a) 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
- Related Articles
- What does the method equals(obj[] a1, obj[] a2) do in java?
- What does the method sort(obj[] a) do in java?
- What does the method toString(obj[] a) do in java?
- What does the method hashCode(int[] a) do in java?
- What does the method remove(obj o) do in java?
- What does the method addElement(E obj) do in java?
- What does the method contains(obj o) do in java?
- What does the method indexOf(obj o) do in java?
- What does the method lastIndexOf(obj o) do in java?
- What does the method set(int, obj o) do in java?
- What does the method sort(obj[] a, int fromIndex, int toIndex) do in java?
- What does the method fill(obj[], object val) do?
- What does the method fill(obj[], int fromIndex, int toIndex, int val) do in java?
- The hashCode() method of CopyOnWriteArrayList method in Java
- What does the method clear() do in java?

Advertisements