I have a list of object array in this structure:
List<Object[]> numbers = new ArrayList<>();
numbers.add(new Object[]{1, 2, 3, 4});
I want to check whether an array of objects exist in that list. The contains method always returns false. I use contains in this way:
if(numbers.contains(new Object[]{1,2,3,4}))
This condition always returns false. What's the problem?
new Something()create a new instance so both yournew Object[]{1, 2, 3, 4}are differents (not the same hashcode)containsmethod usesequalsmethod to find the matching objectequals()sin't overriden and hence you will only be checking referencesList<Object[]>you should useList<List<Object>>