HashSet<String[]> boog = new HashSet<String[]>();
boog.add(new String[]{"a", "b", "c"});
boog.add(new String[]{"a", "b", "c"});
boog.add(new String[]{"a", "b", "d"});
results in
[a, b, c]
[a, b, d]
[a, b, c]
where [a,b,c] is repeated, so the hash function is not working as expected. How would I go about overriding the Hash method for String arrays. Or for that matter, a generic array? Is there a better way to accomplish what I’m trying to do?
You can’t. arrays use the default identity-based Object.hashCode() implementation and there’s no way you can override that. Don’t use Arrays as keys in a HashMap / HashSet!
Use a Set of Lists instead.