Best way to define a hashcode method for char array. Is there a better way to implement our own hascode() method for minimum collision?
char arr1[]={'a','b','c'};
char arr2[]={'b','a','c'};
char arr3[]={'c','a','b'};
int hashcode() {
int p=31;
int n=arr1.length;
int hash=1;
for(int i=0;i<n;i++) {
hash=31*hash+(int)arr1[i];
}
return hash;
}
If you have an object that contains an array of chars and you want to override the hashCode() then you can use the method for It: