I'm unable to explain why you think the array
should have been sorted by doing this, but maybe we can both help each other.
I think that perhaps you have some experience in the C/C++ language, where variables can contain either an object, or a reference to an object, and the same with arrays. By swapping array elements in C++, you're often physically copying objects around.
Note that in
Java, you can never deal with to an "actual object;" all you ever have is a reference to an object. An array element is always a reference to an object, just as a local variable is.
So all Java variables of object type are basically C "dumb pointers." Assigning to a Java variable never changes anything except the value of the variable you actually assign to.
So in your first example, you assign to array elements, and so those array elements change.
But in your second example, you assign to a bunch of local variables, and so only the local variables change; the array is completely untouched.
Does it make sense now?