Possible Duplicate:
Is Java “pass-by-reference”?
I want to know how to pass an object as a parameter to a method by referance in java. I tried this code
public class Class1 
{
    public Class1()
    {
        String x = null;
        F(x);
        //x = null
        System.out.println("x = " + x);
    }
    void F(String x)
    {
        x = "new String";
    }
    public static void main(String[] args)
    {
        new Class1();
    }
}
You can see that I pass a String to a function F and I change String's value inside it, but I can't see the changes I made on it outside the Function F. When I execute this code, I got //{x = null} which is not what I expected //{x = new String}.
 
     
     
     
     
     
    