I am trying to make a contains method where it will search for a name using the compareTo method of the Comparable interface. Here is my problem, It will return true if found but will stay in the while loop and not end if it is not found. AND I CANT FIGURE IT OUT!!!! ive been looking at it for hours and I need help lol
public boolean contains(Celebrities target) {
LinearNode<T> current = contents;
boolean result = false;
while (result == false || current.getNext() != null) {
if (target.compareTo(current.getElement()) == 0)
result = true;
else {
result = false;
current = current.getNext();
}
}
return result;
}
}