You can create strings from arrays before hashing (if the length of the array is not excessively long) in addition to wrapping in List
If you choose the latter, there is a static Arrays method described here From the Java static Arrays class at http://download.oracle.com/javase/1.5.0/docs/api/java/util/Arrays.html #toString (int [ ] )
h1.put(Arrays.toString(test1), s0);
Now you can hash this, and equivalent arrays will hash to the same thing. However, you cannot recreate the array from the key (if Java does not have some kind of eval now?)
.
.
.
,
For curiosity, here I am, stupidly rolling back until I find the method described above:
public String intArrayToString(int[] x) { String ans = '['; for(i = 0; i < size(x); i++) ans += '' + i + ','; return ans + ']'; } HashTable<String,String> h1 = new HashTable<String,String> h1; h1.put(intArrayToString(test1), s0);
If there is some kind of static toString that does this, I apologize. PS - Does Java have a reduction function (and lambdas), a foreach loop or eval (to restore keys to an array, if necessary)? They will make this decision more enjoyable ...
jon_darkstar
source share