Methods with In/Out parameters in Java
Forums:
//All Java parameters are passed by value
void swapStrings(String[] s1, String[] s2){
String temp = s2[0];
s2[0] = s1[0];
s1[0] = temp;
return;
}
String[] s1 = {"A"};
String[] s2 = {"B"};
swapStrings(s1, s2);
//s1[0] is "B", s2[0] is "A"
- Log in to post comments