title: Pass-by-value (StringBuilder vs String)
body: <p>I do not understand why <em>System.out.println(name)</em> outputs <em>Sam</em> without being affected by the method's concat function, while <em>System.out.println(names)</em> outputs <em>Sam4</em> as a result of the method's append method. Why is StringBuilder affected and not String? Normally, calling methods on a reference to an object affects the caller, so I do not understand why the String result remains unchanged. Thanks in advance</p>
  
  <pre><code>public static String speak(String name) {
      name = name.concat("4");
      return name;
  }
  
  public static StringBuilder test(StringBuilder names) {
      names = names.append("4");
      return names; 
  }
  
  public static void main(String[] args) {
      String name = "Sam";
      speak(name);
      System.out.println(name); //Sam
      StringBuilder names = new StringBuilder("Sam");
      test(names);
      System.out.println(names); //Sam4
  }
  </code></pre>