Skip to content
Advertisement

Check if ArrayList Contains same array order ignored

I’ve initialized an ArrayList holding int arrays as such:

ArrayList<int[]> holder = new ArrayList<int[]>();

If I add an int[] like this:

int[] first = {1, 2, 3};

holder.add(first);

If I do this check, I want the function to return true, but it returns false right now

int[] second = {2, 1, 3};

if(holder.contains(second)) return true;

else return false

Advertisement

Answer

You can’t use ArrayList#Contains to judge since int[] don’t have a special equals. You can iterate list and then compare:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement