public class Solution {

```
public ListNode removeElements(ListNode head, int val) {
ListNode current = head;
while(!(current == null)){
if(head.val == val){
head = head.next;
current = head;
}
else if(current.val == val && current.next != null){
current.val = current.next.val;
current.next = current.next.next;
}
else if(current.val == val && current.next == null){
current = null;
}
else{
current = current.next;
}
}
return head;
}
```

}