class Effect
{
public static void main(String [] args)
{
Effect e=new Effect();
e.method();
}
void method()
{
long [] a1 = {3,4,5};
long [] a2 = doArray(a1);
//expected output
System.out.println("After Calling doArray "+a1[1] +" "+ a2[1]);
String s1 = "Hello";
String s2 = doString(s1);
//expected output s1=HelloJava s2=World like earlier arrays
System.out.println("After Calling doString "+s1 + " " + s2);
}
long [] doArray(long [] a3)
{
a3[1] = 7;
System.out.println("In doArray "+ a3[0]+" "+a3[1]+" "+a3[2]);
return a3;
}
String doString(String s1)
{
s1 = s1 + "Java";
System.out.println("In doString "+ s1);
return "World";
}
}
OUTPUT
In doArray 3 7 5
After Calling doArray 7 7
In doString HelloJava
After Calling doString Hello World
My Expected OUTPUT :
After Calling doString HelloJava World
- all array references a1,a2,a3 pointing to same. So, modified data applicable to all
- but in case of String it gives old value even if we modify data
please give some explanation?