I have this function to delete from the list chained by value:
public void deletar(Object valor) {
Node temp = head;
while(temp != null) {
if(temp.getNext().getValor().equals(valor)) {
temp.setNext(temp.getNext().getNext());
break;
} else {
temp = temp.getNext();
}
}
}
But the last element always causes NullPointerException
, does not delete, how do I fix this?