Hi, I am trying to make a function that takes an arraylist and an object as input and checks if the object is in the arraylist. My idea is something like:
boolean includes(Cell[] grid2, Cell tjek){
for (int i=0;i<grid2.size(); i++){
if (grid2.get(i)==tjek){
return true;
}
}
}
However this doesn’t seem to work. Is there a function i can use for checking an arraylist or how can i make a function to check if an object is in the arraylist?
Hello! The problem with your boolean method is that there is a possibility that it doesn’t return a value at all, and boolean methods always have to return a value. Also, you are stating the cell grid as an array, not an arraylist. Try this:
This doesn’t seem to work. it just says the method must return a result of type boolean, but it doesn’t make sense besause it says “return true” or “return false”