How to identify pass-by-value or pass-by reference in Java?
<p>Please pardon the beginner question.I met this code fragment on the internet:</p>

<pre><code>public class Person {

public static void main(String [] args)
{
    StringBuffer a = new StringBuffer("A");
    StringBuffer b = new StringBuffer("B");
    operate(a,b);
    System.out.println(a+","+b);
}


static void operate(StringBuffer x, StringBuffer y)
{
    y.append(x);
    y=x;

 }
}
</code></pre>

<p>I figured out the running output should be A,A, however, the correct output should be A,BA, could expert help me understand why the value of b is still AB? Why "y.append(x)" will affect the value of b, but not "y=x"? That is where I am getting confused. </p>

<p>Thanks in advance.</p>
