JDK-4439572 : Would be nice to have Arrays.hashCode
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 1.4.0
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2001-04-11
  • Updated: 2003-06-20
  • Resolved: 2003-06-20
Related Reports
Duplicate :  
Description
Arrays.equals(byte [], byte []) and the similar methods for different types of
arrays are handy. It would be nice to have Arrays.hashCode(byte []) and similar
methods for the different types of arrays as well. This would provide a single
location for code that is or should be used widely (in hashCode methods for classes where the results of the equals method is based on the contents of an array).

Comments
WORK AROUND You can write your own code to the hash (like this code from String.hashCode): for (int i = 0; i < len; i++) { h = 31*h + val[off++]; }
11-06-2004

SUGGESTED FIX Implement Arrays.hashCode for the same array types that are supported for Arrays.equals, ensuring that if Arrays.equals(a, b) then Arrays.hashCode(a) == Arrays.hashCode(b).
11-06-2004

PUBLIC COMMENTS Arrays.equals(byte [], byte []) and the similar methods for different types of arrays are handy. It would be nice to have Arrays.hashCode(byte []) and similar methods for the different types of arrays as well. This would provide a single location for code that is or should be used widely (in hashCode methods for classes where the results of the equals method is based on the contents of an array).
10-06-2004

EVALUATION This is a reasonable RFE. It is quite analogous to 4751076 (which concerns a content-aware toString method for arrays). ###@###.### 2002-10-07
07-10-2002