HashSet<int[]> a = new HashSet<int[]>();
int[] somestuff = {1, 2, 3};
a.add(somestuff);
int[] somestuff2 = {1, 2, 3};
System.out.println(a.contains(somestuff2));
is false.
How do I check properly? Only when I check for somestuff do i get true, but even if the variable name/literal is not the same, but the values are, I want to get true. what method invocation allows me to get this done? I want to check for values…
Perhaps it has something to do with the contents being hashed in the set and also being dependent on the variable literal that was initially used to populate it
There’s no direct simple way to do what you want, however…
I would create a class that was composed of a
int[]field and implementedequals()and a consistenthashCode()based on the contents of the array.A
Setif such objects could then use: