title: Java - Strings and the substring method
body: <p>I have some question that I wonder about. I know that string are immutable in Java and therefore a new string object is created rather than changed when for example assigning to a existing string object. </p>
  
  <p>Now to my question. Let's suppose that I have the following piece of code:</p>
  
  <pre><code>String a = "Hello World";
  String b = "Hello World";
  
  String res = a.substring(0,4) + b.substring(6,10);
  </code></pre>
  
  <p>How many string objects will be created by the code at line 3 ? Will each call to substring create a new string object ? Will my code above generate 3 new string objects ?</p>
  
  <p>Thanks in advance </p>