Hi,
I am just doing some recap on what I have study so far, and I try this
codes to swap two strings, and it doesn't work. As I learnt, "String"
type is not a primitive type, so when being passed to a method, it
should be passed by reference, but when it comes back from the swap
method, the strings are still the same. How can I make the swap to
work?
public static void main(String[] args) {
String a = "aaa", b = "bbb";
System.out.println("Before swap "
+ "a = " + a
+ " b = " + b);
swap(a, b);
System.out.println("After swap "
+ "a = " + a
+ " b = " + b);
}
static void swap(String x, String y){
String temp = x;
x = y;
y = temp;
}
norman.
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---