Here is the minimum working example:
import java.util.*;
public class Scratchpad {
public static void main(String[] args) {
Collection<int[]> collection = new HashSet<>();
collection.add(new int[]{1,2});
collection.remove(new int[]{1,2});
System.out.println(collection.size());
assert collection.size() == 1;
}
}
The same works for if the items in the collection are of type List
(which implements the equals
method of course).
My suspicion is that it's because array are special objects that does not implement equals
? (If that's case, I feel a little sad that array doesn't get as well documented as other standard library objects, at least not in the Java Docs for the standard lib)