title: Deleting Strings from an ArrayList between 2 specified tags
body: <p>I am trying to remove all elements of an ArrayList between a start and an endtag.</p>
  <p>My list and my tags:</p>
  <pre><code>String startTag = &quot;&lt;p&gt;&quot;;
  String endTag = &quot;&lt;/p&gt;&quot;;
  List&lt;String&gt; elements = new ArrayList&lt;&gt;();
  
  </code></pre>
  <p>Let's say my list looks like this:</p>
  <pre><code>[&lt;text&gt;, &lt;p&gt;, &lt;text&gt;, clean me, &lt;/text&gt;, &lt;/p&gt;, &lt;/text&gt;]
  </code></pre>
  <p>I only want to delete the contents between the sepcified tags and the tags themselves.
  This is my code for doing that:</p>
  <pre><code>       boolean delete = false;
         List&lt;String&gt; remove = new ArrayList&lt;&gt;();
          for(String element : elements) {
              if(delete) {
                  remove.add(element);
              }
  
              if(element.startsWith(startTag)) {
                  delete = true;
                  remove.add(element);
              }
              if(element.endsWith(endTag)) {
                  delete = false;
                  remove.add(element);
              }
          }
          elements.removeAll(remove);
      }
  </code></pre>
  <p>This is how my list &quot;remove&quot; looks like after that:</p>
  <pre><code>[&lt;p&gt;, &lt;text&gt;, clean me, &lt;/text&gt;, &lt;/p&gt;, &lt;/p&gt;]
  </code></pre>
  <p>So after deleting those elements from my list it looks like this:</p>
  <pre><code>[]
  </code></pre>
  <p>When it should look like this:</p>
  <pre><code>[&lt;text&gt;, &lt;/text&gt;]
  </code></pre>
  <p>How can I prevent Strings who have duplicates to be deleted when they are outside of the deletion range?</p>