title: Java: what is faster split in a loop or doing it before
body: <p>Goolge comes up with a lot of comparisions but not on what I am looking for:</p>
  
  <p>What is better if I want to iterate through a splitted String</p>
  
  <pre><code>String[] flagArr = flags.split(";");
  for (String f: flagArr) {
      // some stuff
  }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>for (String f: flags.split(";")) {
      // some stuff
  }
  </code></pre>
  
  <p>With the second pice of code I wonder if the compiler is smart enough to do the split only once </p>