Hi all,
This is my first mail to the group,
i have a question as follows:
class
test {
public static void main(
String arg[])
{
String str1="Hello";
String str2="world";
test.swap(str1,str2);
System.out.println(" Swapped values are :"+ str1+str2);
}
static void swap( String str1,String str2)
{
String temp;
temp=str1;
str1=str2;
str2=temp;
}
}
what i had expect from here is i want to swap the two variable and print the value, i know clearly above function will not print the swapping values due to call by value.
my question here is how can we do the swapping of variable if
java does not suppose call by reference ?
only way i got the solution is make str1 and str2 as class level static variable then it works fine.
but i am expecting any other alternatives for the above question.
i done some research on google to find out the answers but i am uable to get clear answers for it.
please help me out.
Thanks,
sigamala