The method is supposed to check if the linked list has more than one of the same entry. I tried getting the method to check if the head is equal to the current node and then having the current equal to current.next
, if the head never equals the current, i have the head equal to head.next
and restart the current by assigning it to firstNode
. When i try to test the code it gives me the following error:
Exception in thread "main" java.lang.NullPointerException at LinkedBag1.hasDuplicateEntries(LinkedBag1.java:182) java:182 is while((!head.equals(current)) || (current != null)){
Not sure what this means and what is causing my method to make this error appear.
public boolean hasDuplicateEntries(){
Node head = firstNode;
Node current = head.next;
boolean duplicate = true;
while((!head.equals(current)) || (current != null)){
if(head.equals(current)) {
duplicate = true;
}
else{
current = current.next;
}
current = firstNode;
head = head.next;
}
return duplicate;
}
Is there anything I did wrong in my method? Any help will be appreciated.