As I have an ArrayList of int arrays which contains duplicates, I\'d like to use HashSet. Unfortunately, I can\'t manage to use HashSet as I wish:
System.out
Arrays don't override hashCode
and equals
implemented in Object
class, and therefore, two arrays a1 and a2 will be considered as identical to each other by HashSet
only if a1==a2, which is false in your case.
If you use ArrayList
s instead of arrays, your problem will be solved, since for ArrayList
s equality is determined by the equality of the members of the lists (and the order in which they appear).