I have a HashSet of byte[]
s and I would like to test whether a new byte[]
is in that set. The problem is that Java seems to be testing whether the byte[]
instances are the same rather than testing whether the actual values in the byte arrays are the same.
In other words, consider the following code:
public class Test
{
public static void main(String[] args)
{
java.util.HashSet<byte[]> set=new java.util.HashSet<byte[]>();
set.add(new String("abc").getBytes());
System.out.println(set.contains(new String("abc").getBytes()));
}
}
This code prints out false
and I would like it to print out true
. How should I go about doing this?