Here I declare two array lists
ArrayList<Location> possibleMoves = new ArrayList<Location>();
possibleMoves.add(new Location(0, 1));
possibleMoves.add(new Location(1, 0));
ArrayList<Location> possibleMoves1 = new ArrayList<Location>();
possibleMoves1.add(new Location(0, 1));
possibleMoves1.add(new Location(1, 0));
its obvious that those 2 array lists are the same, but when I run this check it always seems to fail.
if(possibleMoves == possibleMoves1){
System.out.println("lol");
}
I have also tried this and it failed
assertTrue("Player 1 1st piece could play to the left and down!",
arrayListsEqual(possibleMoves, possibleMoves1));
this is the method of arrayListsEqual
private boolean arrayListsEqual(ArrayList<Location> a, ArrayList<Location> b) {
if (a.size() != b.size()) {
return false;
}
int size = a.size();
boolean thisOneFound = false;
for (int i = 0; i < size; i++) {
thisOneFound = false;
for (int j = 0; j < size; j++) {
if (a.get(i).equals(b.get(j))) {
thisOneFound = true;
break;
}
}
if (!thisOneFound) {
return false;
}
}
return true;
}