I was working on this code to take in a target String and search the linked list for the target and delete all instances of it. I feel like I have most of the logic down but I am getting a NullPointerException and was needing some help. here is the code:
public class LinkedStringLog implements StringLog {
private LLStringNode head;
private int numOfEntries;
public LinkedStringLog() {//constructor
head = null;
numOfEntries = 0;
}
public void delete(String target){//deletes all entries of target
LLStringNode current = head;
LLStringNode prev = head;
for (int i = 0; i < numOfEntries; i++) {
prev = current;
current = current.getNext();
if (target.equals(current.getValue())){
prev.setNext(current.getNext());
current.setNext(null);
numOfEntries--;
}
}
}