This method:
static void swap(int a, int b) {
int c = a;
a = b;
b = c;
}
does not swap the values of a and b over. It doesn't work for String
variables either. However the following method does swap the first two
elements of the array a[] over.
static void flip(int[] a) {
int c = a[0];
a[0] = a[1];
a[1] = c;
}
So in the first case the method doesn't appear to manipulate its
arguments whereas in the second case it does.
In typing the above I think I may have worked out the answer to the
question I was going to ask. In the first case memory is temporarily
allocated to the variables a and b whereas in the second case the size
of a[] is not known so memory cannot be allocated. This doesn't quite
explain why String variables are not manipulated but I think there is a
default memory allocation for a String variable. It seems that methods
can manipulate array arguments. So is there a general rule as to whether
a method will manipulate its arguments or not?
Paul