title: Deleting an element from a LinkList by a boolean method
body: <p>I'm trying to make my own linkedlist class for a school project, and I'm having trouble with a function I'm supposed to implement.</p>
  <pre><code>    @Override
      public boolean remove(E elementToBeRemoved) {
          MyNode&lt;E&gt; indexNode = first;
          MyNode&lt;E&gt; prevNode = null;
          for (int i = 0; i &lt; lSize; i++) {
              if (indexNode.data.equals(elementToBeRemoved)) {
                  prevNode.next = indexNode.next;
                  indexNode = null;
                  return true;
              }
              prevNode = indexNode;
              indexNode = indexNode.next;
          }
          return false;
      }
  </code></pre>
  <p>How this function is implemented now (to my understanding) is that when I reach the node containing the data I want removed from the list, it removes that node, and returns true indicating that a node has been removed. However this would also mean that I can't remove duplicate nodes in one go, and to remove all instances of elementToBeRemoved I have to use this remove-method multiple times. Is there way I can implement the function so it will remove all nodes in the list that contains elementToBeRemoved in one go?</p>