Reputation: 1270
I have a problem that I need help with. I have a HashSet
that contains char[]
. The problem is that I can't check if a value exists using the method contains()
, it return false even if the value exists in the HashSet
.
How can I resolve this problem ?
Upvotes: 4
Views: 5830
Reputation: 198471
You can't use char[]
in a HashSet
, since the implementation of hashCode()
and equals
for a char[]
is identity-based, not content-based -- in other words, if two char[]
arrays have the same contents, that doesn't mean their hash codes are the same. Use String
instead.
Upvotes: 9