title: Delete multiple nodes from linked list java
body: <p>I'm trying to delete multiples nodes that meets a criteria from a linked list. The program is a bit complex so I'll get state the gist of it. The nodes in my linked list has the following characteristics (a name associated with a number):</p>
  
  <pre><code>Name Number
  Dog     1
  Cat     1
  Rat     2
  Donkey  3
  Fish    1
  </code></pre>
  
  <p>I want to be able to delete the nodes with the number 1. My delete function:</p>
  
  <pre><code>public void Delete(Int N) {
  
          Node current = Head;
          Node previous = Head;
  
  
          while (current.getNum() != N) {
  
              if (current.getNextNode() == null) {
  
                  System.out.print("Not found");
  
              } else {
  
                  previous = current;
  
                  current = current.getNextNode();
  
              }
  
          }
  
          if (current == Head) {
  
              Head = Head.getNextNode();
  
          } else {
  
              Node A = current.getNextNode();
              previous.setNextNode(A);
  
          }
  
      }
  </code></pre>
  
  <p>This works but it only removes the first occurrence. I know it may be due to the lack of or appropriate loop structure but I've been working on this for hours and I'm getting confused along the way. I've tried doing a trace table manually but that's not working either. </p>
  
  <p>How can the function be edited so it loops through the entire linked lists and removes the nodes that matches the criteria? </p>