title: Java replace all replacing one of every two occurrences
body: <p>I have a strange behavior on a really simple problem. </p>
  
  <p>I have a string with a lot of null strings:    </p>
  
  <blockquote>
    <p>"a;b;c;null;null;null;null;null;null;null;null;null;null"</p>
  </blockquote>
  
  <p>Which I remove using this method:</p>
  
  <pre><code>public String replaceAllNull(String s) {
      s = s.replaceAll(";null;", ";;");
  
      //if first item = null remove it
      if(s.startsWith("null;")) {
          s = s.substring(4,s.length());
      }
  
      //if last item = null remove it
      if(s.endsWith(";null")) {
          s = s.substring(0,s.length()-4);
      }
      return s;
  }
  </code></pre>
  
  <p>It was working fine until my string became bigger and I saw this strange output</p>
  
  <blockquote>
    <p>"a;b;c;;null;;null;;null;;null;;"</p>
  </blockquote>
  
  <p>It's only removing one occurrence out of two.</p>
  
  <p>I think I can understand that during one replace program skips one ";" then the second null is not recognized by my regex ";null;". But I don't get why is this happening?</p>