案例一:
public class test1 {
public static void mb_swap(String Str1,String Str2) {
String temp=Str1;
Str1=Str2;
Str2=temp;
}
public static void main(String[] arg) {
String str1="A";
String str2="B";
mb_swap(str1,str2);
System.out.print(str1+" "+str2);
}
}
输出str1与str2结果为“A”、“B”
案例二:
public static void mb_swap(String[] s) {
if (s.length < 2)
return;
String t = s[0];
s[0] = s[1];
s[1] = t;
}
public static void main(String[] arg) {
String[] s = { "1", "2" };
mb_swap(s);
System.out.print(s[0] + s[1]);
}
输出结果:21