title: Java for loop by value or by reference
body: <p>I figured out a a problem in my Code. First the code:</p>
  
  <pre><code>public class Main {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
          String[] blablubb = { "a", "b", "c" };
  
          for(String s : blablubb) {
              s = "over";
          }
          printArray(blablubb);
  
  
          for (int i = 0; i &lt; blablubb.length; i++) {
              blablubb[i] = "over";
          }
          printArray(blablubb);
  
      }
  
      public static void printArray(String[] arr) {
          for( String s : arr ) {
              System.out.println(s);
          }
      }
  
  }
  </code></pre>
  
  <p>The output is:</p>
  
  <pre><code>a
  b
  c
  over
  over
  over
  </code></pre>
  
  <p>I assumed the first loop would also overwrite the String in the array. So the output would be over in any case. It seems it creates a copy of the value instead creating a reference.
  I never perceived this. Am I doing it wrong? Is there an option to create a reference instead?</p>
  
  <p>//Edit:
  Seems like everybody knows about that except me. I'm from C background and doesn't pay enough attention to the term reference which is very different to C. 
  Fortunately it took me just 10 minutes to figure this out (this time).</p>