java - NPE when searching element in the LinkedList -


i'm searching element in linkedlist, output correct when element indeed in list. however, testing opposite case, when searching null or element not in list, npe happens. please help, thanks!

public boolean find(e e){     node current=head;     while(current.item !=null){         if(e.equals(current.item)){             system.out.println("true");             return true;         }         current=current.next;     }     system.out.println("false");     return false; } 

the while statement should while(current !=null)


Comments