Using the program, my professor gave me, when node p reaches the last node shouldn't it exit the loop? How would I delete the last Node?
|____|--->|____|--->|HERE|--->|NULL|
When P reaches to the last node. It satisfies p.next!=null. Hence it can never remove the last Node.
Although the outer for loop goes till the 2nd last element say p, the if condition in it "p.next.element.equals(e)" checks for the element after p, i.e. the last element when p is 2nd last. So the element that you check for deleting is actually p.next while p always keeps a pointer to the previous element. That way p.next = p.next.next ends up deleting p.next.