Always think that Java 's method parameters are passed values, after the call does not affect itself.
Java does not have a pointer in C + + , in the fast sort, the incoming array, but the value of the change occurred. This leads to thinking:
For the convenience of example, the following is a partial quick sort pseudo-code
In the recursive array, the array values are manipulated.
void quickSort (intintint r) { if (L < r) { -1); + 1, R); } }
Conclusion: A value is passed in theJava method parameter, in which the parameter is a reference type (such as an array), and the value of the memory address of the arrays is passed in, which can be manipulated.
Principle:
the mechanisms in Java are as follows:
( explained in ---Java core Technology • Volume 1 )
Basic data types (byte,int,char,long,float, Double,boolean , and short)
The reference type (reference type) points to an object, not the original value, and the variable that points to the object is a reference variable.
(like a pointer in C + +, a special way to point to an object entity (a specific value), to store a memory address)
Note:String , Array, interface, class are reference types.
Discussion of arrays:
Int[] A=new int[3]; Double[] B=new double[3];
String[] S=new string[3]; Example[] E=new example[3];
Regardless of the type of array (), the array identifier (a,b,s,e) is actually just a reference to a real object created in the heap.
Object array (s, e) is the same on use, the only difference ( value saved in array )
( refer to Java programming idea 16.2 section array why special )
The reference in Java is equivalent to a restricted pointer, and a reference is obtained when new creates the object.
such as String Ex=new string ("example");
Therefore, in the recursive operation of the fast sort, the address value of the array is passed in, and the array is manipulated in each recursion, and the values of the arrays are actually changed.
Caishuxueqian, improper place, hope to correct.
Reference: <java Core Technology • Volume 1> Chapter 4.2 Method Parameters
Advanced reading:<java programming ideas > Why is an array special
Java method Parameters-think of something interesting