I have written a method in Java which takes in an array list which contains another array of size 3 as each element. e.g. {{0,0,0},{1,0,0},{1,1,0}...}.
The method works out if the head of the queue is inside this array list.
The queue has the same structure as the array list.
public static Queue<Integer[]> q = new LinkedList<Integer[]>();
List<Integer[]> outcomes = new ArrayList<Integer[]>();
Public static boolean outcomeSearch(List<Integer[]> outcomes){
boolean check = false;
for (int i=0; i<outcomes.size(); i++){
if (q.peek() == outcomes.get(i)){
check = true;
}
}
return check;
}
For some reason, I can't get the if statement to work. In practice, the head of the queue is {0,0,0} and outcomes is {{0,0,0},{8,0,0},{0,5,0}...}. So the for loop should turn the check boolean true in the first iteration. But it doesn't.
This problem is comparing elements inside the array, not the whole array itself.