The problem is that your setNext(Element next)
method does not set anything if next == null
. And that is the case for the last element of your list.
So when you call delete.setNext(delete.getNext().getNext());
, nothing is actually set because delete.getNext().getNext()
is null
!
Remove the if (next != null)
condition in setNext
and it will work.